Views
No views yet
apply_chat_template to show you how to load the tokenizer and model and how to generate contents.1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "prithivMLmods/QwQ-LCoT-7B-Instruct"
4
5model = AutoModelForCausalLM.from_pretrained(
6 model_name,
7 torch_dtype="auto",
8 device_map="auto"
9)
10tokenizer = AutoTokenizer.from_pretrained(model_name)
11
12prompt = "How many r in strawberry."
13messages = [
14 {"role": "system", "content": "You are a helpful and harmless assistant. You are Qwen developed by Alibaba. You should think step-by-step."},
15 {"role": "user", "content": prompt}
16]
17text = tokenizer.apply_chat_template(
18 messages,
19 tokenize=False,
20 add_generation_prompt=True
21)
22model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
23
24generated_ids = model.generate(
25 **model_inputs,
26 max_new_tokens=512
27)
28generated_ids = [
29 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
30]
31
32response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
safetensors) for efficient storage and download:
model-00001-of-00004.safetensors (4.88 GB)model-00002-of-00004.safetensors (4.93 GB)model-00003-of-00004.safetensors (4.33 GB)model-00004-of-00004.safetensors (1.09 GB)vocab.json (2.78 MB)merges.txt (1.82 MB)tokenizer.json (11.4 MB)special_tokens_map.json (e.g., <pad>, <eos>).config.json: Defines model architecture and hyperparameters.generation_config.json: Settings for inference and text generation tasks.