Instructions to use mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection") model = AutoModelForCausalLM.from_pretrained("mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection") 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 mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection
- SGLang
How to use mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection 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 "mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection" \ --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": "mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection", "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 "mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection" \ --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": "mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection with Docker Model Runner:
docker model run hf.co/mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection
Qwen2.5-1.5B-Instruct-CoT-Reflection
This model has been finetuned from the Qwen2.5-1.5B-Instruct Model. This model has been finetuned on data to produce step by step chain of thought responses with reflections. This model was trained with unsloth with LoRA and 4 bit quantization.
How to use?
It is recommended to use the prompt mentioned in the code snippet to get the best responses.
NOTE: IGNORE THE BACKSLASH '\' BEFORE THE TRIPLE BACK TICKS IN THE PROMPT
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Qwen/Qwen2.5-1.5B-Instruct"
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
user_instruction = """You are given a query below. Please read it carefully and approach the solution in a step-by-step manner.
Query:
{query}
Your task is to provide a detailed, logical, and structured solution to the query following the format outlined below:
\```
<thinking> In this section, break down the task and develop a clear, step-by-step plan to solve it. Use chain of thought reasoning, where \
you work through each step thoughtfully and logically, reflecting on each part of the process as you go. Write each step thoroughly, addressing \
all key points and presenting them in numbered steps (1, 2, 3, ...). After each step, include a reflection. The reflection serves to validate \
your reasoning. If any part of the reasoning seems flawed, correct it here. <reflection> This is where you reflect upon your reasoning for \
this step. If any part of your thought process seems flawed, correct it here and continue. </reflection> </thinking>
<output> Once the thinking process is complete, provide the final solution in this section. Ensure that your final answer is concise and focused on the core solution. </output>
\```
Approach the query using the outlined method, ensuring each step is carefully reasoned and verified before moving forward."""
query = "A snail is at the bottom of a 20-foot well. Each day, it climbs up 3 feet, but at night, it slips back 2 feet. How many days will it take for the snail to reach the top of the well?\n\nAlso, let's try to avoid one-line answers and provide some reasoning to the solution."
messages = [
{"role": "system", "content": "You are a thoughtful AI assistant. Analyze each query step by step, considering all relevant details. Evaluate different possible solutions, reflecting on the advantages and drawbacks of each. Provide a clear and concise answer, explaining the reasoning behind each step and how you arrived at the solution."},
{"role": "user", "content": user_instruction.format(query=query)}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=3072,
temperature=0.2,
top_p=0.9,
do_sample=True,
repetition_penalty=1.1,
top_k=20,
use_cache=True
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
- Downloads last month
- 7
Model tree for mosama/Qwen2.5-1.5B-Instruct-CoT-Reflection
Base model
Qwen/Qwen2.5-1.5B