Views
No views yet
Sahibsingh12/gemma3-1b-thinking, which is a PEFT (Parameter-Efficient Fine-Tuning) adapter for google/gemma-3-1b-it. Unlike a full model, this is a lightweight adapter that works alongside the base model, making it easier to distribute and use with limited resources.torch
transformers
peftpip install torch transformers peft1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel, PeftConfig
3
4# Load the base model and tokenizer
5base_model_id = "google/gemma-3-1b-it"
6tokenizer = AutoTokenizer.from_pretrained(base_model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 base_model_id,
9 device_map="auto", # Automatically determine the device
10 torch_dtype="auto" # Use the appropriate precision
11)
12
13# Load the PEFT adapter
14adapter_model_id = "Sahibsingh12/gemma3-1b-thinking"
15model = PeftModel.from_pretrained(model, adapter_model_id)
16
17# Generate text
18prompt = "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?"
19inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
20outputs = model.generate(
21 inputs,
22 max_new_tokens=128,
23 do_sample=True,
24 temperature=0.7,
25 top_p=0.9,
26)
27
28response = tokenizer.decode(outputs[0], skip_special_tokens=True)
29print(response)1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4# Load the base model and tokenizer
5base_model_id = "google/gemma-3-1b-it"
6tokenizer = AutoTokenizer.from_pretrained(base_model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 base_model_id,
9 device_map="auto",
10 torch_dtype="auto"
11)
12
13# Load the PEFT adapter
14adapter_model_id = "Sahibsingh12/gemma3-1b-thinking"
15model = PeftModel.from_pretrained(model, adapter_model_id)
16
17# Prepare chat messages
18messages = [
19 {"role": "user", "content": "Calculate the area of a circle with radius 5cm"}
20]
21
22# Format messages for the model
23prompt = tokenizer.apply_chat_template(
24 messages,
25 tokenize=False,
26 add_generation_prompt=True
27)
28
29# Generate response
30inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
31outputs = model.generate(
32 inputs,
33 max_new_tokens=256,
34 do_sample=True,
35 temperature=0.7,
36)
37
38response = tokenizer.decode(outputs[0], skip_special_tokens=True)
39print(response)1from transformers import pipeline
2
3# Initialize the pipeline with the adapter model
4generator = pipeline(
5 "text-generation",
6 model="Sahibsingh12/gemma3-1b-thinking",
7 model_kwargs={"device_map": "auto", "torch_dtype": "auto"}
8)
9
10# Generate text
11question = "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?"
12output = generator(
13 [{"role": "user", "content": question}],
14 max_new_tokens=128,
15 do_sample=True,
16 temperature=0.7,
17 return_full_text=False
18)[0]
19
20print(output["generated_text"])| Argument | Description | Default |
|---|---|---|
--prompt | Input text for generation | "If you had a time machine..." |
--base-model | Hugging Face base model name | "google/gemma-3-1b-it" |
--adapter | Hugging Face adapter model name | "vinhnx90/gemma3-1b-thinking" |
--device | Computing device (cpu, cuda, mps, or auto) | "auto" |
--max-tokens | Maximum number of new tokens to generate | 128 |
--temperature | Sampling temperature | 0.7 |
--top-p | Top-p sampling parameter | 0.9 |
1@article{zhihong2024deepseekmath,
2 title = {{DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models}},
3 author = {Zhihong Shao and Peiyi Wang and Qihao Zhu and Runxin Xu and Junxiao Song and Mingchuan Zhang and Y. K. Li and Y. Wu and Daya Guo},
4 year = 2024,
5 eprint = {arXiv:2402.03300},
6}1@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édec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}1@misc{peft,
2 title = {{PEFT: Parameter-Efficient Fine-Tuning of Billion-Scale Models on Low-Resource Hardware}},
3 author = {Younes Belkada and Thomas Wang and Yasmine Manar and Ajay Brahmakshatriya and Huu Nguyen and Yongwei Zhou and Soumya Batra and Neil Band and Romi Ponciano and Suraj Patil and Colin Raffel and Siddhartha Kamalakara and Enrico Shippole and Vesselin Popov and Lewis Tunstall and Brian Mugo and Patrick von Platen and Clémentine Fourrier and Surya Dantuluri and Luke Vilnis and Adam P. Saxton},
4 year = 2023,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/peft}}
8}