Spaces:
Runtime error
Runtime error
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| device = "cpu" # the device to load the model onto | |
| model = AutoModelForCausalLM.from_pretrained( | |
| "NTQAI/Nxcode-CQ-7B-orpo", | |
| torch_dtype="auto", | |
| device_map="auto" | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained("NTQAI/Nxcode-CQ-7B-orpo") | |
| prompt = """Complete the following Python function: | |
| from typing import List | |
| def has_close_elements(numbers: List[float], threshold: float) -> bool: | |
| """ | |
| messages = [ | |
| {"role": "user", "content": prompt} | |
| ] | |
| inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device) | |
| outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id) | |
| res = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True) | |