- This automatically downloads the model and tokenizer files
- Define your test query
- Construct Qwen-style messages
- Convert the messages into the Qwen prompt format
- Tokenize the prompt
- Generate the response
- Remove the prompt tokens from the generation to isolate the assistant’s response
- Decode the generated tokens
- **Finetuned from model [optional]: Qwen/Qwen2.5-Coder-7B-Instruct ** [More Information Needed]
How to Get Started with the Model
Use the code below to get started with the model.
from transformers import AutoTokenizer, AutoModelForCausalLM from transformers import AutoModelForCausalLM, AutoTokenizer import torch
model_name = "huge-michael/sylvan-model"
This automatically downloads the model and tokenizer files
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, device_map="auto")
model.eval()
Define your test query
prompt = """ write a function def process_and_analyze_csv_data(df) to: Processes and analyzes a CSV dataset for train-test split, feature scaling, and data statistics.
The function should output with: dict: A dictionary containing train/test split data, scaled features, and statistical data.
You should start with: ['pandas as pd', 'numpy as np', 'train_test_split', 'StandardScaler'] def process_and_analyze_csv_data(df)"""
Construct Qwen-style messages
messages = [ {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."}, {"role": "user", "content": prompt} ]
Convert the messages into the Qwen prompt format
text = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True # adds the Assistant role placeholder for generation )
Tokenize the prompt
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
Generate the response
with torch.no_grad(): outputs = model.generate( **model_inputs, max_new_tokens=800, temperature=0.7, # adjust for randomness top_p=0.9 # adjust for response diversity )
Remove the prompt tokens from the generation to isolate the assistant’s response
generated_ids = [ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, outputs) ]
Decode the generated tokens
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print("Assistant response:\n", response)
[More Information Needed]
- Downloads last month
- 2