CreitinGameplays/Raiden-DeepSeek-R1-llama3.1-v1
Viewer • Updated • 62.9k • 4
How to use CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1")
model = AutoModelForCausalLM.from_pretrained("CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1")
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]:]))How to use CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1
How to use CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1" \
--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": "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1" \
--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": "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1 with Docker Model Runner:
docker model run hf.co/CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1
Chat template format:
<|start_header_id|>system<|end_header_id|>
You are focused on providing systematic, well-reasoned responses. Response Structure: - Format: <think>{{reasoning}}</think>{{answer}} - Reasoning: Minimum 6 logical steps only when it required in <think> block - Process: Think first, then answer.
You are a helpful AI assistant named Llama, made by Meta AI.
<|eot_id|><|start_header_id|>user<|end_header_id|>
How many r's are in strawberry?<|eot_id|><|start_header_id|>assistant<|end_header_id|><think>
Run this model:
# test the model
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
def main():
model_id = "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1"
# Load the tokenizer.
tokenizer = AutoTokenizer.from_pretrained(model_id, add_eos_token=True)
# Load the model using bitsandbytes 8-bit quantization if CUDA is available.
if torch.cuda.is_available():
model = AutoModelForCausalLM.from_pretrained(
model_id,
load_in_8bit=True,
device_map="auto"
)
device = torch.device("cuda")
else:
model = AutoModelForCausalLM.from_pretrained(model_id)
device = torch.device("cpu")
# Define the generation parameters.
generation_kwargs = {
"max_new_tokens": 2048,
"do_sample": True,
"temperature": 0.5,
"top_p": 0.9,
"repetition_penalty": 1.1,
"num_return_sequences": 1,
"forced_eos_token_id": tokenizer.eos_token_id,
"pad_token_id": tokenizer.eos_token_id
}
print("Enter your prompt (type 'exit' to quit):")
while True:
# Get user input.
user_input = input("Input> ")
if user_input.lower().strip() in ("exit", "quit"):
break
# Construct the prompt in your desired format.
prompt = f"""
<|start_header_id|>system<|end_header_id|>
You are focused on providing systematic, well-reasoned responses. Response Structure: - Format: <think>{{reasoning}}</think>{{answer}} - Reasoning: Minimum 6 logical steps only when it required in <think> block - Process: Think first, then answer.
You are a helpful AI assistant named Llama, made by Meta AI.
<|eot_id|><|start_header_id|>user<|end_header_id|>
How many r's are in strawberry?<|eot_id|><|start_header_id|>assistant<|end_header_id|><think>
"""
# Tokenize the prompt and send to the selected device.
input_ids = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=True).to(device)
# Create a new TextStreamer instance for streaming responses.
streamer = TextStreamer(tokenizer)
generation_kwargs["streamer"] = streamer
print("\nAssistant Response:")
# Generate the text (tokens will stream to stdout via the streamer).
outputs = model.generate(input_ids, **generation_kwargs)
if __name__ == "__main__":
main()
Or alternatively:
import torch
from transformers import pipeline
model_id = "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1"
pipe = pipeline(
"text-generation",
model=model_id,
torch_dtype=torch.bfloat16,
device_map="auto"
)
messages = [{"role": "user", "content": "hello there!"}]
outputs = pipe(
messages,
temperature=0.5,
repetition_penalty=1.1,
max_new_tokens=2048
)
print(outputs[0]["generated_text"][-1])