mirror of
https://github.com/zenlm/zen-coder.git
synced 2026-11-10 21:30:01 +00:00
- Rename Qwen2.5-Coder-* examples to zen-coder-* (consistent Zen branding) - Add LLM.md knowledge base (symlinked as CLAUDE.md/AGENTS.md/etc.) - Update .gitignore: exclude model weights and AI symlink files - Add training configs, inference scripts, test suite - Add MLX README, model card, Makefile for common operations
19 lines
893 B
Python
19 lines
893 B
Python
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
device = "cuda" # the device to load the model onto
|
|
|
|
# Now you do not need to add "trust_remote_code=True"
|
|
tokenizer = AutoTokenizer.from_pretrained("zenlm/zen-coder")
|
|
model = AutoModelForCausalLM.from_pretrained("zenlm/zen-coder", device_map="auto").eval()
|
|
|
|
|
|
# tokenize the input into tokens
|
|
input_text = "#write a quick sort algorithm"
|
|
model_inputs = tokenizer([input_text], return_tensors="pt").to(device)
|
|
|
|
# Use `max_new_tokens` to control the maximum output length.
|
|
generated_ids = model.generate(model_inputs.input_ids, max_new_tokens=1024, do_sample=False)[0]
|
|
# The generated_ids include prompt_ids, so we only need to decode the tokens after prompt_ids.
|
|
output_text = tokenizer.decode(generated_ids[len(model_inputs.input_ids[0]):], skip_special_tokens=True)
|
|
|
|
print(f"Prompt: {input_text}\n\nGenerated text: {output_text}")
|