Views
No views yet
1from peft import AutoPeftModelForCausalLM
2from transformers import AutoTokenizer
3
4base_model = "HuggingFaceTB/SmolLM3-3B-Base"
5instruct_model = "HuggingFaceTB/SmolLM3-3B"
6adapter_model = "psHf/SmolLM3-Custom-SFT"
7
8# Load the adapter and automatically merge with the base
9model = AutoPeftModelForCausalLM.from_pretrained(adapter_model)
10tokenizer = AutoTokenizer.from_pretrained(instruct_model)
11
12# If needed, merge permanently:
13# model = model.merge_and_unload()
14
15text = "Hello, how are you?"
16inputs = tokenizer(text, return_tensors="pt")
17
18with torch.no_grad():
19 instruct_outputs = model.generate(
20 **inputs,
21 max_new_tokens=150,
22 temperature=0.7,
23 do_sample=True,
24 pad_token_id=tokenizer.eos_token_id
25 )
26 instruct_response = tokenizer.decode(instruct_outputs[0], skip_special_tokens=True)
27
28 # Extract only the assistant's response
29 assistant_start = instruct_response.find("<|im_start|>assistant\n") + len("<|im_start|>assistant\n")
30 assistant_response = instruct_response[assistant_start:].split("<|im_end|>")[0]
31 print(assistant_response)
32
33
34<!-- from transformers import pipeline
35
36question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
37generator = pipeline("text-generation", model="psHf/SmolLM3-Custom-SFT", device="cuda")
38output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
39print(output["generated_text"]) -->HuggingFaceTB/SmolLM3-3B-Base1@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}