Instructions to use kehanlu/llama-3.2-8B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kehanlu/llama-3.2-8B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="kehanlu/llama-3.2-8B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("kehanlu/llama-3.2-8B-Instruct") model = AutoModelForCausalLM.from_pretrained("kehanlu/llama-3.2-8B-Instruct") 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]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use kehanlu/llama-3.2-8B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kehanlu/llama-3.2-8B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kehanlu/llama-3.2-8B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/kehanlu/llama-3.2-8B-Instruct
- SGLang
How to use kehanlu/llama-3.2-8B-Instruct 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 "kehanlu/llama-3.2-8B-Instruct" \ --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": "kehanlu/llama-3.2-8B-Instruct", "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 "kehanlu/llama-3.2-8B-Instruct" \ --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": "kehanlu/llama-3.2-8B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use kehanlu/llama-3.2-8B-Instruct with Docker Model Runner:
docker model run hf.co/kehanlu/llama-3.2-8B-Instruct
This repository contains the text-only LLM portion of meta-llama/Llama-3.2-11B-Vision-Instruct
How it was done
from collections import OrderedDict
from transformers import MllamaForConditionalGeneration, AutoModelForCausalLM
from transformers.models.mllama.modeling_mllama import MllamaCrossAttentionDecoderLayer
llama32_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
llama32 = MllamaForConditionalGeneration.from_pretrained(
llama32_id,
torch_dtype=torch.bfloat16,
device_map="cuda:0",
)
new_layers = []
for idx, layer in enumerate(llama32.language_model.model.layers):
if isinstance(layer, MllamaCrossAttentionDecoderLayer):
# CrossAttention layers are only take effect when image is provided.
# Ignore here since we want text-only model
pass
else:
new_layers.append(layer)
llama32.language_model.model.cross_attention_layers = []
llama32.language_model.model.layers = torch.nn.ModuleList(new_layers)
# Now llama32.language_model is identical to Llama3.1-8B-Instruct, except the embedding size(+8)
# see: https://github.com/huggingface/transformers/blob/a22a4378d97d06b7a1d9abad6e0086d30fdea199/src/transformers/models/mllama/modeling_mllama.py#L1667C9-L1667C26
new_llama32_state_dict = OrderedDict()
for k, v in llama32.language_model.state_dict().items():
if k == "model.embed_tokens.weight":
v = v[:128256, :]
new_llama32_state_dict[k] = v
# Load a llama31 for the architecture
llama31_id = "meta-llama/Llama-3.1-8B-Instruct"
llama31 = AutoModelForCausalLM.from_pretrained(
llama31_id,
torch_dtype=torch.bfloat16,
device_map="cuda:1",
)
llama31.load_state_dict(new_llama32_state_dict)
# <All keys matched successfully>
llama31.save_pretrained("./my-cool-llama3.2")
Note:
In the original tokenizer, there are date_string in tokenizer.chat_template (which append the current date when calling tokenizer.apply_chat_template(messages)).
I removed this behavior in this repo. Please be aware when you use AutoTokenizer.from_pretrained(this_repo).
- Downloads last month
- 91