Views
No views yet
transformers library:pip install transformers torch1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Replace with your Hugging Face repo ID
5model_id = "joe-xhedi/Qwen-GRPO-training"
6
7# Load the tokenizer
8tokenizer = AutoTokenizer.from_pretrained(
9 model_id,
10 trust_remote_code=True,
11 padding_side="right"
12)
13if tokenizer.pad_token is None:
14 tokenizer.pad_token = tokenizer.eos_token
15
16# Load the model
17device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
18model = AutoModelForCausalLM.from_pretrained(
19 model_id,
20 trust_remote_code=True,
21 torch_dtype=torch.bfloat16
22).to(device)
23
24# Example usage (assuming you have a 'messages' list prepared)
25inputs = tokenizer("Your prompt here", return_tensors="pt").to(device)
26outputs = model.generate(**inputs)
27response = tokenizer.decode(outputs[0], skip_special_tokens=True)
28print(response)trust_remote_code=True flag allows the tokenizer and model to execute code from the repository. Use with caution.torch_dtype=torch.bfloat16 for better memory optimization.