Views
No views yet
unsloth/gemma-4-E2B-it that reshapes the model's reasoning style into concise bulleted thinking traces while keeping the final answers intact.Thinking Process: blocks, this adapter makes the model emit a short flat - bullet list inside a <|channel>thought ... <channel|> block, then the answer — exactly the condensed reasoning style it was trained on.| File | Why |
|---|---|
adapter_model.safetensors | The trained LoRA weights (12.08M params, ~46 MB) |
adapter_config.json | LoRA config (r=8, alpha=8, target modules) |
tokenizer.json, tokenizer_config.json, chat_template.jinja | Gemma4 tokenizer + chat template |
chat.py | Ready-to-run interactive chat script (streaming) |
README.md | This file |
This is a LoRA adapter only, not a standalone model. You load the base model (unsloth/gemma-4-E2B-it) and apply this adapter on top — see below.
1pip install torch transformers peft
2python chat.pychat.py auto-detects CUDA / Intel XPU / CPU, loads the base model, applies this adapter, merges it, and starts a streaming chat with thinking ON. In-chat commands: /q quit · /reset clear history · /raw show special-token markers · /think toggle thinking.1import torch
2from transformers import AutoModelForCausalLM, AutoProcessor
3from peft import PeftModel
4
5BASE = "unsloth/gemma-4-E2B-it"
6ADAPTER = "xbruce22/gemma-4-e2b-reasoning-lora"
7
8device = "cuda" if torch.cuda.is_available() else (
9 "xpu" if hasattr(torch, "xpu") and torch.xpu.is_available() else "cpu")
10dtype = torch.float32 if device == "cpu" else torch.bfloat16
11
12base = AutoModelForCausalLM.from_pretrained(BASE, dtype=dtype).to(device)
13model = PeftModel.from_pretrained(base, ADAPTER)
14# Optional: merge LoRA into the weights for faster inference
15model = model.merge_and_unload()
16model.eval()
17
18processor = AutoProcessor.from_pretrained(BASE)
19
20messages = [
21 {"role": "system", "content": "You are a helpful assistant."},
22 {"role": "user", "content": "Write DFS in python, keep short."},
23]
24text = processor.apply_chat_template(
25 messages, tokenize=False, add_generation_prompt=True, enable_thinking=True)
26
27inputs = processor(text=[text], return_tensors="pt").to(device)
28# Text-only: drop multimodal-only fields generate() rejects
29for k in list(inputs):
30 if "token_type" in k or "pixel" in k or "audio" in k:
31 inputs.pop(k)
32
33with torch.inference_mode():
34 out = model.generate(
35 **inputs, max_new_tokens=1024, do_sample=True,
36 temperature=1.0, top_p=0.95, top_k=64,
37 pad_token_id=processor.tokenizer.pad_token_id)
38
39gen = out[0][inputs["input_ids"].shape[1]:]
40print(processor.decode(gen, skip_special_tokens=True))enable_thinking=True to apply_chat_template so the template injects <|think|> and the model produces the <|channel>thought ... <channel|> reasoning block before the answer.temperature=1.0, top_p=0.95, top_k=64.merge_and_unload(), keep using the PeftModel directly — both work.Write DFS in python, keep short.── thinking ──
- User wants a DFS implementation in Python, explicitly requesting it be "short"
- Settled on iterative version using a stack and visited set ...
- Concise version: no classes, just a function — keeps it short while remaining correct
── answer ──
def dfs(graph, start, visited=None):
...q/k/v/o_proj) + MLP (gate/up/down_proj) modules. Vision and audio towers frozen (text-only finetune).Jackrong/GLM-5.1-Reasoning-1M-Cleaned (main subset). The verbose imd…answer thinking traces were condensed into terse flat bullet lists (via a condenser prompt); the original final answers were kept verbatim.<|channel>thought\n...bullets...\n<channel|> then the final answer, <|turn> turn markers, assistant-only loss (user/system tokens masked to -100).adamw_torch, gradient checkpointing. No 4-bit / bitsandbytes (no XPU build).unsloth/gemma-4-E2B-it follows Gemma's terms.