lablab-ai-amd-developer-hackathon/Resep-ID-Gemma-4
Resep ID Gemma 4
This Space explains an end-to-end fine-tuning project: taking google/gemma-4-e2b-it, adapting it to Indonesian recipe generation, evaluating the result, quantizing it to GGUF, and deploying it as a lightweight recipe assistant.
The goal was simple:
Given an Indonesian dish title, generate a structured recipe withBahan:andLangkah:in natural Bahasa Indonesia.
Example input:
Tulis resep masakan Indonesia berjudul: "Tumis Kangkung Tempe".Expected output shape:
Bahan:
- ...
- ...
Langkah:
1. ...
2. ...Project Summary
Why Fine-Tune?
The base Gemma 4 model was already fluent in Indonesian, but it often missed the identity of specific Indonesian dishes.
For example, the base model could produce a plausible recipe, but not always the right recipe. It struggled with regional or highly specific dishes such as:
- Sosis Solo
- Tahu Thek
- Tempe Mendoan
- Tahu Walik Aci
- Kering Tempe Pete
- DEBM / MPASI recipe variants
A baseline evaluation on 50 held-out recipes showed the main gap:
The key weakness was dish_authenticity: the model was fluent, but too often produced a generic Indonesian recipe instead of the requested dish.
Dataset
The dataset contains structured Indonesian home-cooking recipes.
Each row has:
The project converts the original parquet files into JSONL splits:
data/processed/train.jsonl
data/processed/val.jsonl
data/processed/test.jsonlThe held-out test split is not used for training. It is used only for pre/post fine-tune comparison.
Training Setup
The fine-tune used a single AMD MI300X GPU on ROCm 7.2.
Important training choices:
- Full fine-tune instead of LoRA
- bf16 training
- 1 epoch
- Effective batch size 16
- Max sequence length 2048
- Cosine learning-rate schedule
- 3% warmup
- Gradient checkpointing enabled
- Vision/audio paths frozen because this task is text-only
Gemma 4 is multimodal, but this project trains only the text path:
Train:
- model.language_model.*
- lm_head
Freeze:
- vision tower
- audio tower
- vision/audio adaptersTraining Format
The project uses TRL prompt/completion conversational format:
{
"prompt": [
{
"role": "user",
"content": "Tulis resep masakan Indonesia berjudul: \"Tumis Kangkung Tempe\"..."
}
],
"completion": [
{
"role": "assistant",
"content": "Bahan:\n- ...\n\nLangkah:\n1. ..."
}
]
}This format was important. In this stack, the alternative messages format with assistant_only_loss=True caused unstable loss behavior.
Results
The fine-tuned model improved the practical recipe-generation behavior.
The strongest gains were:
- More consistent
Bahan:/Langkah:formatting - Better recipe length discipline
- More natural Indonesian cooking vocabulary
- Better common-dish ingredient profiles
- Better structure for common dishes like tumis, pepes, rendang, sambal, and gulai
Critical Inference Setting
One important lesson from the project: the fine-tuned model needs repetition control.
For Hugging Face Transformers inference, use:
model.generate(
**inputs,
max_new_tokens=1280,
do_sample=False,
repetition_penalty=1.05,
no_repeat_ngram_size=6,
pad_token_id=tok.eos_token_id,
)Without no_repeat_ngram_size=6, long recipes can fall into repeated ingredient-list loops.
For GGUF runtimes such as llama.cpp or LM Studio, use the DRY sampler equivalent with allowed length around 6.
GGUF Deployment
The model was also converted to GGUF for local and CPU-friendly use.
Available quantizations:
The GGUF model can run with llama.cpp, LM Studio, or other GGUF-compatible runtimes.
What Worked
The project worked well for:
- Common Indonesian home-cooking recipes
- Structured recipe generation
- Concise recipe output
- Natural Indonesian recipe phrasing
- Common ingredients and cooking methods
Examples of stronger categories:
- Ayam
- Ikan
- Sapi
- Kambing
- Tahu
- Tempe
- Telur
- Udang
- Sambal
- Tumis
- Pepes
- Rendang-style dishes
Limitations
This is not a perfect cookbook model.
Known limitations:
- Rare regional dishes can become generic.
- Some defining ingredients may be omitted.
- Diet or modifier terms such as MPASI, DEBM, basah, or kering may be ignored.
- The model may produce plausible but not authentic recipes.
- Some outputs may contain minor formatting or fraction glitches.
- Recipes should be checked before cooking.
The main remaining bottleneck is dataset coverage, especially for regional and specialty dishes.
Lessons Learned
The biggest technical lessons:
- Use the native ROCm 7.2 PyTorch wheel on MI300X.
- Avoid older ROCm wheels for this Gemma 4 bf16 training path.
- Use prompt/completion format with TRL for this stack.
- Always run a cheap quick-validation training pass before a full run.
- Judge the base model before fine-tuning.
- Automatic metrics are not enough for recipe quality.
no_repeat_ngram_size=6is critical for stable inference.- Dataset coverage matters more than another epoch for rare dishes.
Cost and Runtime
The full successful cycle was inexpensive because MI300X training was fast for this model size.
Approximate reference run:
Future cycles should be cheaper because the stack and gotchas are now documented.
Links
- Base model: `google/gemma-4-e2b-it`
- Fine-tuned model: `junwatu/resep-ID-gemma-4-E2B-it`
- GGUF model: `junwatu/resep-ID-gemma-4-E2B-it-gguf`
- Dataset: `junwatu/indonesian-recipes`
- Live recipe demo: `junwatu/koki-ai`
License
This project inherits the Gemma Terms of Use from the base model.
