🧠 Model Card for gemma-3n-gek408-dpo
gemma-3n-gek408-dpo is a high-performance, fine-tuned version of
google/gemma-3n-E2B-it, meticulously optimized for educational and scientific reasoning. This model was trained leveraging the
Unsloth library for significantly faster training and reduced memory usage.
The training followed a two-stage process:
- Supervised Fine-Tuning (SFT): To teach the model the desired instruction-following behavior on scientific and mathematical tasks.
- Direct Preference Optimization (DPO): To align the model's responses with human preferences for clarity, accuracy, and helpfulness.
This model was developed for the
Google - The Gemma 3n Impact Challenge competition.
📌 Model Details
🧾 Model Description
- Developed by: Argobell
- Shared by: Argobell
- Model type: Multimodal model, capable of processing text image and audio inputs.
- Finetuned from:
google/gemma-3n-E2B-it
- License: This model is subject to the Gemma Terms of Use. Users must agree to and comply with the Gemma Terms of Use and the Gemma Prohibited Use Policy.
- Primary Domain: Education, STEM, Visual Reasoning
📂 Model Sources
🎯 Uses
✅ Direct Use
This model is ideal for:
- 🧮 Math Tutoring Agents: Guiding students through complex math problems.
- 🧑🏫 Educational AI Assistants: Answering questions based on educational materials.
- 📊 Diagram-based Question Answering: Interpreting charts, graphs, and scientific diagrams.
- 🔍 Visual Reasoning & Explanation: Explaining logical steps from a visual prompt.
🧩 Downstream Use
This model serves as a strong foundation for:
- Create interactive, offline-ready learning experiences for students in low-connectivity regions.
- Advanced multimodal AI systems for educational platforms.
- Domain-specific reasoning tools for science and engineering.
- Interactive learning applications in STEM fields.
⚠️ Bias, Risks, and Limitations
This model inherits limitations common to most LLMs and has specific risks related to its application:
- Hallucination: The model can generate incorrect or fabricated information.
- Prompt Sensitivity: The phrasing of a prompt can significantly affect the output quality.
- Inherited Biases: It may reflect biases present in the
gemma-3n-E2B-it base model and the gek408 dataset.
- Risk of "Fluent Nonsense": In educational contexts, the model might generate explanations that sound logical and correct but contain subtle mathematical or scientific inaccuracies. Human verification is crucial for factual and educational use cases.
💡 Recommendations
Always critically evaluate the model's output before use in any real-world application. For educational purposes, outputs should be reviewed by a subject matter expert.
🚀 Getting Started
The model was trained with Unsloth, so using it for inference is recommended for maximum performance.
1from unsloth import FastModel
2import torch
3from transformers import TextStreamer
4import gc
5
6# Load the model and tokenizer with 4-bit quantization
7model, tokenizer = FastModel.from_pretrained(
8 model_name = "Argobell/gemma-3n-gek408-dpo",
9 max_seq_length = 1024, # Choose any for long context!
10 load_in_4bit = True, # 4 bit quantization to reduce memory
11 # token = "hf_...", # use one if using gated models
12)
13
14# Helper function for inference
15def do_gemma_3n_inference(model, messages, max_new_tokens = 128):
16 inputs = tokenizer.apply_chat_template(
17 messages,
18 add_generation_prompt = True, # Must add for generation
19 tokenize = True,
20 return_dict = True,
21 return_tensors = "pt",
22 ).to("cuda")
23 _ = model.generate(
24 **inputs,
25 max_new_tokens = max_new_tokens,
26 temperature = 1.0, top_p = 0.95, top_k = 64,
27 streamer = TextStreamer(tokenizer, skip_prompt = True),
28 )
29 # Cleanup to reduce VRAM usage
30 del inputs
31 torch.cuda.empty_cache()
32 gc.collect()
33
34sloth_link = "https://files.worldwildlife.org/wwfcmsprod/images/Sloth_Sitting_iStock_3_12_2014/story_full_width/8l7pbjmj29_iStock_000011145477Large_mini__1_.jpg"
35
36messages = [{
37 "role" : "user",
38 "content": [
39 { "type": "image", "image" : sloth_link },
40 { "type": "text", "text" : "Which films does this animal feature in?" }
41 ]
42}]
43# You might have to wait 1 minute for Unsloth's auto compiler
44do_gemma_3n_inference(model, messages, max_new_tokens = 256)
🛠️ Training Details
The training was conducted in two distinct phases, using a LoRA-based approach accelerated by Unsloth.
📚 Phase 1: Supervised Fine-Tuning (SFT)
- Goal: To teach the model the fundamental structure of responding to mathematical prompts.
- Dataset:
Argobell/gek408
- Key Hyperparameters: The following parameters were used to tune both the vision and language components of the model.
1# SFT Stage Configuration
2--max_seq_length 2048
3--max_steps 320
4--learning_rate 2e-4
5--lr_scheduler_type "cosine"
6--optim "adamw_torch_fused"
7
8# LoRA Configuration
9--tune_vision
10--tune_language_layers
11--tune_attention_modules
12--tune_mlp_modules
13--r 16
14--alpha 16
15--lora_dropout 0.05
16
17# Batching & Memory
18--per_device_train_batch_size 4
19--per_device_eval_batch_size 4
20--gradient_accumulation_steps 8
21--gradient_checkpointing
22
📚 Phase 2: Direct Preference Optimization (DPO)
- Goal: To refine the SFT model by training it to prefer helpful, accurate responses over less desirable ones.
- Dataset:
Argobell/gek408-dpo
- Key Hyperparameters: Starting from the SFT-tuned model, DPO training was performed with the following settings.
1# DPO Stage Configuration
2--max_seq_length 2048
3--max_prompt_length 1024
4--max_steps 100
5--learning_rate 5e-6
6--optim "adamw_torch_fused"
7--warmup_ration 0.1
8--weight_decay 0.01
9
10# LoRA Configuration
11--tune_vision
12--tune_language_layers
13--tune_attention_modules
14--tune_mlp_modules
15--r 4
16--alpha 4
17--lora_dropout 0.1
18
19# Batching & Memory
20--per_device_train_batch_size 2
21--per_device_eval_batch_size 2
22--gradient_accumulation_steps 4
23--gradient_checkpointing
24
💻 Infrastructure & Software
- Hardware: 1× NVIDIA RTX 5880 Ada Generation
- Key Software:
- Unsloth: Used for 2-3x faster training and ~60% less memory usage, enabling more extensive experimentation.
- Hugging Face TRL: For implementing the SFT and DPO training loops.
- Hugging Face Transformers & Datasets.
🧰 Technical Specifications
Architecture
Gemma-3n utilizes a Matryoshka Transformer (MatFormer) architecture, which nests smaller, self-contained models within a larger one.
🙏 Acknowledgements
This work would not have been possible without the foundational models and libraries developed by the open-source community. We would like to extend our gratitude to:
- Google: For developing and releasing the powerful gemma-3n-E2B-it base model.
- The Unsloth AI team: For creating the Unsloth library, which was instrumental in accelerating the training process and reducing computational costs.
- Hugging Face: For providing the transformers, datasets, and TRL libraries that formed the backbone of our training and experimentation pipeline.
📖 Citation
If you use this model in your work, please cite it as follows:
1@misc{gemma3ngek408dpo,
2 author = {Argobell},
3 title = {gemma-3n-gek408-dpo},
4 howpublished = {\url{https://huggingface.co/Argobell/gemma-3n-gek408-dpo}},
5 year = {2025}
6}
👥 Model Card Authors
📬 Contact
For questions, feedback, or collaboration, please reach out via email:
argocot@gmail.com