Instructions to use yujiepan/llama-3-tiny-random with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yujiepan/llama-3-tiny-random with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yujiepan/llama-3-tiny-random") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("yujiepan/llama-3-tiny-random") model = AutoModelForCausalLM.from_pretrained("yujiepan/llama-3-tiny-random") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use yujiepan/llama-3-tiny-random with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yujiepan/llama-3-tiny-random" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yujiepan/llama-3-tiny-random", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/yujiepan/llama-3-tiny-random
- SGLang
How to use yujiepan/llama-3-tiny-random with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "yujiepan/llama-3-tiny-random" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yujiepan/llama-3-tiny-random", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "yujiepan/llama-3-tiny-random" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yujiepan/llama-3-tiny-random", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use yujiepan/llama-3-tiny-random with Docker Model Runner:
docker model run hf.co/yujiepan/llama-3-tiny-random
Update README.md
Browse files
README.md
CHANGED
|
@@ -19,11 +19,14 @@ import transformers
|
|
| 19 |
import torch
|
| 20 |
import os
|
| 21 |
from huggingface_hub import create_repo, upload_folder
|
|
|
|
| 22 |
|
| 23 |
source_model_id = 'meta-llama/Meta-Llama-3-8B-Instruct'
|
| 24 |
save_path = '/tmp/yujiepan/meta-llama-3-tiny-random'
|
| 25 |
repo_id = 'yujiepan/meta-llama-3-tiny-random'
|
| 26 |
|
|
|
|
|
|
|
| 27 |
config = transformers.AutoConfig.from_pretrained(
|
| 28 |
source_model_id,
|
| 29 |
trust_remote_code=True,
|
|
@@ -40,6 +43,10 @@ model = transformers.AutoModelForCausalLM.from_config(
|
|
| 40 |
config,
|
| 41 |
trust_remote_code=True,
|
| 42 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
model = model.to(torch.bfloat16)
|
| 44 |
model.save_pretrained(save_path)
|
| 45 |
|
|
@@ -52,6 +59,8 @@ tokenizer.save_pretrained(save_path)
|
|
| 52 |
model.float().generate(torch.tensor([[1, 2, 3]]).long(), max_length=16)
|
| 53 |
|
| 54 |
os.system(f'ls -alh {save_path}')
|
|
|
|
| 55 |
create_repo(repo_id, exist_ok=True)
|
| 56 |
-
upload_folder(repo_id=
|
|
|
|
| 57 |
```
|
|
|
|
| 19 |
import torch
|
| 20 |
import os
|
| 21 |
from huggingface_hub import create_repo, upload_folder
|
| 22 |
+
import accelerate
|
| 23 |
|
| 24 |
source_model_id = 'meta-llama/Meta-Llama-3-8B-Instruct'
|
| 25 |
save_path = '/tmp/yujiepan/meta-llama-3-tiny-random'
|
| 26 |
repo_id = 'yujiepan/meta-llama-3-tiny-random'
|
| 27 |
|
| 28 |
+
os.system(f'rm -rf {save_path}')
|
| 29 |
+
|
| 30 |
config = transformers.AutoConfig.from_pretrained(
|
| 31 |
source_model_id,
|
| 32 |
trust_remote_code=True,
|
|
|
|
| 43 |
config,
|
| 44 |
trust_remote_code=True,
|
| 45 |
)
|
| 46 |
+
|
| 47 |
+
with accelerate.init_empty_weights():
|
| 48 |
+
model.generation_config = transformers.AutoModelForCausalLM.from_pretrained(source_model_id).generation_config
|
| 49 |
+
|
| 50 |
model = model.to(torch.bfloat16)
|
| 51 |
model.save_pretrained(save_path)
|
| 52 |
|
|
|
|
| 59 |
model.float().generate(torch.tensor([[1, 2, 3]]).long(), max_length=16)
|
| 60 |
|
| 61 |
os.system(f'ls -alh {save_path}')
|
| 62 |
+
# os.system(f'rm -rf {save_path}/model.safetensors')
|
| 63 |
create_repo(repo_id, exist_ok=True)
|
| 64 |
+
upload_folder(repo_id='yujiepan/meta-llama-3-tiny-random', folder_path=save_path)
|
| 65 |
+
upload_folder(repo_id='yujiepan/llama-3-tiny-random', folder_path=save_path)
|
| 66 |
```
|