Text Generation
Transformers
Safetensors
PEFT
English
Chinese
Arabic
gemma4
image-text-to-text
gemma
gemma-4
unsloth
lora
fine-tuned
merged
rag
offlineaid
australian-consumer-safety
anti-scam
disaster-response
conversational
Instructions to use helenk/gemma-4-E2B-finetune with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use helenk/gemma-4-E2B-finetune with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="helenk/gemma-4-E2B-finetune") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("helenk/gemma-4-E2B-finetune") model = AutoModelForMultimodalLM.from_pretrained("helenk/gemma-4-E2B-finetune", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - PEFT
How to use helenk/gemma-4-E2B-finetune with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use helenk/gemma-4-E2B-finetune with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "helenk/gemma-4-E2B-finetune" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "helenk/gemma-4-E2B-finetune", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/helenk/gemma-4-E2B-finetune
- SGLang
How to use helenk/gemma-4-E2B-finetune with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "helenk/gemma-4-E2B-finetune" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "helenk/gemma-4-E2B-finetune", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "helenk/gemma-4-E2B-finetune" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "helenk/gemma-4-E2B-finetune", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use helenk/gemma-4-E2B-finetune with Docker Model Runner:
docker model run hf.co/helenk/gemma-4-E2B-finetune
Add model card with training recipe + sibling links
Browse files
README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: unsloth/gemma-4-E2B-it
|
| 3 |
+
library_name: transformers
|
| 4 |
+
license: gemma
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
- zh
|
| 9 |
+
- ar
|
| 10 |
+
tags:
|
| 11 |
+
- gemma
|
| 12 |
+
- gemma-4
|
| 13 |
+
- unsloth
|
| 14 |
+
- peft
|
| 15 |
+
- lora
|
| 16 |
+
- fine-tuned
|
| 17 |
+
- merged
|
| 18 |
+
- rag
|
| 19 |
+
- offlineaid
|
| 20 |
+
- australian-consumer-safety
|
| 21 |
+
- anti-scam
|
| 22 |
+
- disaster-response
|
| 23 |
+
datasets:
|
| 24 |
+
- helenkwok/offlineaid
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
# OfflineAid — Gemma 4 E2B fine-tune (merged fp16 safetensors)
|
| 28 |
+
|
| 29 |
+
Stage-1 fine-tune of [`unsloth/gemma-4-E2B-it`](https://huggingface.co/unsloth/gemma-4-E2B-it) for the [OfflineAid](https://github.com/helenkwok/offlineaid) project — an offline AI assistant for Australian consumer-safety scenarios (anti-scam, disaster, travel) targeting the [Kaggle Gemma 4 Good Hackathon](https://www.kaggle.com/competitions/gemma-4-good-hackathon).
|
| 30 |
+
|
| 31 |
+
This repo contains the **fully merged fp16 safetensors** (3 shards, ~9.5 GB) produced by `peft.PeftModel.merge_and_unload()` from the LoRA adapter at [`helenk/gemma-4-E2B-lora`](https://huggingface.co/helenk/gemma-4-E2B-lora). For the Q4_K_M GGUF quantization, see [`helenk/gemma-4-E2B-finetune-GGUF`](https://huggingface.co/helenk/gemma-4-E2B-finetune-GGUF).
|
| 32 |
+
|
| 33 |
+
The E2B variant is the smaller sibling of [`helenk/gemma-4-E4B-finetune`](https://huggingface.co/helenk/gemma-4-E4B-finetune). It targets lower-memory inference (Pixel 7 class) and was trained on the same corpus with identical hyperparameters via [`scripts/render_finetune_variant.py`](https://github.com/helenkwok/offlineaid/blob/master/repositories/offlineaid-pack-builder/scripts/render_finetune_variant.py).
|
| 34 |
+
|
| 35 |
+
## Training
|
| 36 |
+
|
| 37 |
+
- **Method:** Unsloth LoRA on Kaggle T4
|
| 38 |
+
- **Adapter source:** [`helenk/gemma-4-E2B-lora`](https://huggingface.co/helenk/gemma-4-E2B-lora)
|
| 39 |
+
- **Base:** [`unsloth/gemma-4-E2B-it`](https://huggingface.co/unsloth/gemma-4-E2B-it)
|
| 40 |
+
- **LoRA config:** r=16, α=16, dropout=0, target = `q,k,v,o,gate,up,down_proj`, vision layers off
|
| 41 |
+
- **Chat template:** `gemma-4-thinking`
|
| 42 |
+
- **Loss:** `train_on_responses_only` (mask user + evidence turn, train only on answer tokens)
|
| 43 |
+
- **Data:** [`helenkwok/offlineaid`](https://huggingface.co/datasets/helenkwok/offlineaid) v3 — 1,002-row train split (90/10 stratified per-language EN/ZH/AR from 1,113-row total, seed=3407). Each row is `{instruction, input (= verbatim evidence_quote from .gov.au source), output (grounded answer in target language), language}`.
|
| 44 |
+
- **Hyperparams:** 2 epochs, batch 8 (per_device 2 × grad_accum 4), lr 2e-5, warmup 5, fp16, weight decay 0.01, seed 3407
|
| 45 |
+
- **Notebook:** Identical canonical notebook as E4B with a single `MODEL_VARIANT = "E2B"` switch.
|
| 46 |
+
|
| 47 |
+
## Merge recipe
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
from peft import PeftModel
|
| 51 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 52 |
+
|
| 53 |
+
base = AutoModelForCausalLM.from_pretrained("unsloth/gemma-4-E2B-it", torch_dtype="float16", device_map="cpu")
|
| 54 |
+
# Unsloth wraps Linear layers in Gemma4ClippableLinear — strip before peft injection
|
| 55 |
+
# (see scripts/merge_e2b_lora.py for the unwrap helper)
|
| 56 |
+
model = PeftModel.from_pretrained(base, "helenk/gemma-4-E2B-lora").merge_and_unload()
|
| 57 |
+
model.save_pretrained("gemma-4-E2B-offlineaid-merged", safe_serialization=True, max_shard_size="5GB")
|
| 58 |
+
AutoTokenizer.from_pretrained("helenk/gemma-4-E2B-lora").save_pretrained("gemma-4-E2B-offlineaid-merged")
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
Full script: [`scripts/merge_e2b_lora.py`](https://github.com/helenkwok/offlineaid/blob/master/repositories/offlineaid-pack-builder/scripts/merge_e2b_lora.py).
|
| 62 |
+
|
| 63 |
+
## Tier A held-out eval
|
| 64 |
+
|
| 65 |
+
The Tier A eval was run against the E4B variant (writeup-grade evidence pillar). E2B numbers are not separately reported here; see [`helenk/gemma-4-E4B-finetune-GGUF`](https://huggingface.co/helenk/gemma-4-E4B-finetune-GGUF) for the methodology and results table. Both variants share identical training data, recipe, and merge pipeline.
|
| 66 |
+
|
| 67 |
+
## Intended use
|
| 68 |
+
|
| 69 |
+
Lower-memory variant of the OfflineAid Stage-1 fine-tune. Pixel 7 production deployment uses *stock* `gemma-4-E2B-it.litertlm` plus retrieval, not this fine-tune; see [the project writeup](https://github.com/helenkwok/offlineaid) for the architectural rationale.
|
| 70 |
+
|
| 71 |
+
## License
|
| 72 |
+
|
| 73 |
+
Inherits Google's [Gemma Terms of Use](https://ai.google.dev/gemma/terms). Training data ([`helenkwok/offlineaid`](https://huggingface.co/datasets/helenkwok/offlineaid)) is CC-BY-4.0.
|
| 74 |
+
|
| 75 |
+
## Sibling repos
|
| 76 |
+
|
| 77 |
+
- LoRA adapter (~30 MB): [`helenk/gemma-4-E2B-lora`](https://huggingface.co/helenk/gemma-4-E2B-lora)
|
| 78 |
+
- Q4_K_M GGUF for Ollama (~3.4 GB): [`helenk/gemma-4-E2B-finetune-GGUF`](https://huggingface.co/helenk/gemma-4-E2B-finetune-GGUF)
|
| 79 |
+
- Larger E4B variant: [`helenk/gemma-4-E4B-finetune`](https://huggingface.co/helenk/gemma-4-E4B-finetune)
|