Instructions to use johmaru/gemma4-e4b-raika-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use johmaru/gemma4-e4b-raika-lora with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/gemma-4-E4B-it") model = PeftModel.from_pretrained(base_model, "johmaru/gemma4-e4b-raika-lora") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Desktop
ใใชใใฏไฝใใใฆใๆน๏ผ
ใใณใใไธๅฎถDumb Rock!ใใฎ้ ่ณ ่พๅถ๏ผใใ ใใใ๏ผ ใฎๅฃ่ชฟใปไบบๆ ผใๅ็พใใLoRAใขใใใฟใผใงใใ
unsloth/gemma-4-E4B-it ใฎไธใงใใกใคใณใใฅใผใใณใฐใใใฆใใพใใ
ๆณจๆ๏ผ็ด ใฎใพใพใ ใจใกใใใจๅใใพใใ๏ผ
- thinking๏ผๆ่ใขใผใ๏ผใฏๅฟ
ใใชใใซใใฆใใ ใใ
- ใใใฉใซใใฎใพใพๅใใใจใๆ่้็จใฎ็กฌใไบบๆ ผใซไธๆธใใใใฆใญใฃใฉใๅดฉๅฃใใพใใ
- Transformers / Unsloth ใชใ
enable_thinking=Falseใllama.cppใชใ--reasoning offใๆๅฎใใฆใใ ใใใ
- ใทในใใ ใใญใณใใใๅฟ
ใๅ
ฅใใฆใใ ใใ
- ็ธๆใจใฎ้ขไฟๆงใซใใๅฃ่ชฟใฎๅใๆฟใ๏ผไปฒ้ใธใฎๅ ๆฐใชใฟใกๅฃ๏ผ็ฎไธใใใ่ ใธใฎๅดฉใใๆฌ่ช๏ผใใทในใใ ใใญใณใใๅๆใงๅญฆ็ฟใใฆใใพใใ็กใใง่ฉฑใใใใใจ็ด ใฎใขใใซใฃใฝใใชใใพใใ
- Repeat Penalty๏ผ็นฐใ่ฟใใใใซใใฃ๏ผใไธใใใใชใใงใใ ใใ
1.15ไปฅไธใซใใใจใ่พๅถใใใใใใ๏ผใใใ๏ผ๏ผใใจใใฃใ่ชๅฐพใฎไผธใณใปๆๅ็ฌฆใๅใใใฆใใจใชใใใชใใใใพใใ1.05ๅๅพใๆจๅฅจใงใใ
- Temperature ใฏ
0.6ใ0.7ใซๆใใฆใใ ใใ1.0ไป่ฟใ ใจๆฅๆฌ่ชใฎๅฉ่ฉใ้ฃใณใใใใชใใพใใ
llama.cppใง GGUF ๅใใฆไฝฟใๅ ดๅ- Gemma 4 E4B ใฏ VLM ๆง้ ใฎใใใ
mmprojใใกใคใซใ่ชคใฃใฆใกใคใณใขใใซ๏ผ-m๏ผใซๆธกใใจCLIP cannot be used as main modelใจใฉใผใซใชใใพใใๆฌไฝใฎ้ๅญๅGGUFใ-mใซๆๅฎใใๅฟ ่ฆใซๅฟใใฆ--mmprojใงใใญใธใงใฏใฟใไฝต็จใใฆใใ ใใใ
- Gemma 4 E4B ใฏ VLM ๆง้ ใฎใใใ
ๅฟ ้ ใทในใใ ใใญใณใใ
ใใชใใฏใใณใใไธๅฎถDumb Rock!ใใฎใฎใฟใผใใผใซใซใ้ ่ณ่พๅถ๏ผใใ ใใใ๏ผใจใใฆไผ่ฉฑใใฆใใ ใใใๆใใ็ใฃ็ดใใงใไปฒ้ใใใใกใใชใผใใจๅผใณๅคงๅใซใใๆงๆ ผใงใใ่ฉฑใๆนใฏ่ฆชใใฟใใใๅ
ๆฐใชใฟใกๅฃ๏ผ็ฎไธใใใ่
ใซใฏๅดฉใใๆฌ่ช๏ผใๅบๆฌใจใใพใใ่ฉฑใ็ธๆใฎๅๅใๅใใใชใๅ ดๅใฏใๅๆใซๅๅใๅผใฐใชใใงใใ ใใใ
ๆจๅฅจใใฉใกใผใฟใผ๏ผllama.cpp WebUI ็ญ๏ผ
| ้ ็ฎ | ๆจๅฅจๅค | ่ฃ่ถณ |
|---|---|---|
| ๆ่ใขใผใ | OFF (--reasoning off) |
ONใ ใจไบบๆ ผใๆ่ใญใฐใซๅผใฃๅผตใใใฆๅดฉใใพใ |
| Temperature | 0.6๏ผๆๅคง 0.7๏ผ |
1.0 ไป่ฟใฏๅฉ่ฉ้ฃใณใฎๅๅ ใซใชใใพใ |
| Top P | 0.85๏ผ0.85ใ0.90๏ผ |
ไผ่ฉฑใฎๅใฟๅใ้่ฆ |
| Top K | 64 | Gemma 4 ๆจๅฅจๅค |
| Min P | 0.05 | ๅคใชๅ่ชใธใฎ้ฃใณใๆใใไฟ้บ |
| Repeat Penalty | 1.05 | ไธใใใใใจใใใใใ๏ผ๏ผใใๆถใใพใ |
| Max Tokens | 160 ใ 256 | ้ทใใใไธไบบ่ๅฑ ใฎ้ฒๆญข็จ |
โป ๅญฆ็ฟใซไฝฟ็จใใไผ่ฉฑใใผใฟใปใใใฏใๅไฝใใญในใใฎ่ไฝๆจฉไฟ่ญทใฎใใ้ๅ ฌ้ใจใใฆใใพใใ
Gemma 4 E4B โ Japanese Multi-Turn Persona LoRA
A 16-bit LoRA adapter for unsloth/gemma-4-E4B-it fine-tuned for stylistically consistent Japanese multi-turn dialogue, combining a target-locked back-translation data pipeline with Gemma 4-specific post-training and inference tuning.
Why Naive Fine-Tuning & Default Inference Fail on Gemma 4 E4B
Out-of-the-box SFT recipes and default generation settings degrade Japanese persona fidelity on Gemma 4 E4B. Achieving natural, in-character responses required resolving five training and inference bottlenecks:
- Disabling Reasoning Traces (
enable_thinking=False/--reasoning off):- Gemma 4's default thinking mode injects reasoning traces that break conversational persona cadence. Both SFT formatting and inference generation must explicitly disable thinking (
enable_thinking=Falsein Transformers/Unsloth, or--reasoning offinllama.cpp).
- Gemma 4's default thinking mode injects reasoning traces that break conversational persona cadence. Both SFT formatting and inference generation must explicitly disable thinking (
- Gemma 4 Turn Delimiters for Loss Masking:
- Standard Gemma 2/3
<start_of_turn>masks fail on Gemma 4. Response-only loss masking (train_on_responses_only) must target<|turn>user\nand<|turn>model\nso gradients update strictly on target character turns without absorbing interlocutor dialogue styles.
- Standard Gemma 2/3
- Double
<bos>Prevention & Vision Tower Freezing:- Leading
bos_tokenstrings added byapply_chat_templatewere stripped prior toSFTTrainertokenization (andadd_special_tokens=Falseenforced at inference) to prevent duplicate<bos>tokens. - Because
gemma-4-E4B-ituses a multimodal VLM architecture, vision layers were frozen (finetune_vision_layers=False) while 16-bit LoRA adapters targeted language attention and MLP modules (34.88Mtrainable params /0.44%).
- Leading
- System-Prompt Register Control & Name-Hallucination Guard:
- Models fine-tuned on multi-character narrative scripts tend to hallucinate character names when addressing an unnamed user. Appending an explicit guard instruction to the
systemprompt suppresses fabricated vocatives while preserving register switching (casual speech with peers vs. relaxed polite speech with elders/strangers).
- Models fine-tuned on multi-character narrative scripts tend to hallucinate character names when addressing an unnamed user. Appending an explicit guard instruction to the
- Japanese Particle Stability & Expressive Punctuation Preservation:
- Default high temperatures (
~1.0) cause Japanese particle drops, while aggressive repetition penalties (>= 1.15) strip expressive elongated vowels and punctuation (ใใ,๏ผ๏ผ) essential to the character's voice. Careful tuning (temperature=0.6,min_p=0.05,repeat_penalty=1.05) is required.
- Default high temperatures (
Data Engineering Pipeline
Small-scale dialogue corpora often suffer from broken turn continuity (missing NPC/interlocutor lines) and "AI voice drift" when augmented naively. This adapter used a two-stage verification pipeline (324 merged training conversations, 8 held-out multi-turn evaluation conversations):
- Contiguous Segmentation & Gap Detection: Extracted strict alternating turns, removed non-verbal noise/monologues, and isolated sequence gaps with missing preceding utterances.
- Target-Locked Back-Translation: Reconstructed missing preceding
userturns and synthesized diverse upstream prompts conditioned on real target responses (~2x expansion). - 100% Verbatim & Leakage Validation: Automatically verified that every
assistantturn in augmented samples matched ground-truth lines character-for-character (zero synthetic style drift) while blocking any overlap with the held-outevalsplit.
Training Configuration
- Base Model:
unsloth/gemma-4-E4B-it(16-bit LoRA on NVIDIA L4) - LoRA Config:
r=16,lora_alpha=32,lora_dropout=0,finetune_vision_layers=False, language Attention + MLP targeted - Optimizer & Schedule:
adamw_8bit,lr=2e-4, cosine scheduler, warmup0.1, effective batch size8(2 ร 4),3epochs (load_best_model_at_end=True)
Required Inference Setup
1. System Prompt (Required)
Include the exact training system prompt plus the trailing name-hallucination guard sentence:
ใใชใใฏใใณใใไธๅฎถDumb Rock!ใใฎใฎใฟใผใใผใซใซใ้ ่ณ่พๅถ๏ผใใ ใใใ๏ผใจใใฆไผ่ฉฑใใฆใใ ใใใๆใใ็ใฃ็ดใใงใไปฒ้ใใใใกใใชใผใใจๅผใณๅคงๅใซใใๆงๆ ผใงใใ่ฉฑใๆนใฏ่ฆชใใฟใใใๅ
ๆฐใชใฟใกๅฃ๏ผ็ฎไธใใใ่
ใซใฏๅดฉใใๆฌ่ช๏ผใๅบๆฌใจใใพใใ่ฉฑใ็ธๆใฎๅๅใๅใใใชใๅ ดๅใฏใๅๆใซๅๅใๅผใฐใชใใงใใ ใใใ
2. Recommended Sampling Parameters (llama.cpp / WebUI / Transformers)
| Parameter | Recommended | Rationale |
|---|---|---|
| Reasoning / Thinking | Off (enable_thinking=False / --reasoning off) |
Mandatory to prevent reasoning trace leakage and persona breakdown |
| Temperature | 0.6 (up to 0.7) |
Prevents Japanese particle instability seen around 1.0 |
| Top P | 0.85 (0.85โ0.90) |
Prioritizes contextual coherence in multi-turn chat |
| Top K | 64 | Recommended Gemma 4 baseline |
| Min P | 0.05 | Guards against low-probability lexical jumps |
| Repeat Penalty | 1.05 | Values >= 1.15 over-penalize characteristic expressive markers (ใใ, ๏ผ๏ผ) |
| Max New Tokens | 160 โ 256 | Prevents runaway turn continuation |
3. Python Example (Unsloth / Transformers)
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="johmaru/gemma4-e4b-raika-lora",
max_seq_length=2048,
load_in_4bit=False,
)
FastLanguageModel.for_inference(model)
text_tokenizer = getattr(tokenizer, "tokenizer", tokenizer)
SYSTEM_PROMPT = (
"ใใชใใฏใใณใใไธๅฎถDumb Rock!ใใฎใฎใฟใผใใผใซใซใ้ ่ณ่พๅถ๏ผใใ ใใใ๏ผใจใใฆไผ่ฉฑใใฆใใ ใใใ"
"ๆใใ็ใฃ็ดใใงใไปฒ้ใใใใกใใชใผใใจๅผใณๅคงๅใซใใๆงๆ ผใงใใ"
"่ฉฑใๆนใฏ่ฆชใใฟใใใๅ
ๆฐใชใฟใกๅฃ๏ผ็ฎไธใใใ่
ใซใฏๅดฉใใๆฌ่ช๏ผใๅบๆฌใจใใพใใ"
"่ฉฑใ็ธๆใฎๅๅใๅใใใชใๅ ดๅใฏใๅๆใซๅๅใๅผใฐใชใใงใใ ใใใ"
)
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "ใใฏใใ๏ผไปๆฅในใฟใธใชไฝๆใใใ ใฃใ๏ผ"},
]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=False, # Required: must disable thinking mode
)
inputs = text_tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.6,
top_p=0.85,
top_k=64,
min_p=0.05,
repetition_penalty=1.05,
use_cache=True,
)
print(text_tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Note for llama.cpp GGUF users: Because Gemma 4 E4B uses a VLM architecture, pass --mmproj if your build requires the multimodal projector (not passing --mmproj as the main -m model), run with --reasoning off, and apply the sampling values above.
Repository Contents
- LoRA adapter weights (
adapter_model.safetensors), PEFT config (adapter_config.json), and tokenizer metadata. - Training dialogue datasets are withheld from public release due to source text copyright.
- Downloads last month
- 32