Gemma 4 E2B Bible Q&A — ONNX (q4 for Transformers.js / WebGPU)

Otozure/gemma4-e2b-bible-ONNX is a 4-bit quantized ONNX (q4) version of Gemma 4 E2B-it, fine-tuned with Unsloth on Otozure/gotquestionsdotorg (9,504 cleaned Christian theology question-and-answer pairs) and packaged specifically for client-side WebGPU and Node.js inference via @huggingface/transformers v4 (transformers.js).

Highlights

  • 100% client-side / local inference: Runs directly in modern browsers via WebGPU (or WASM/CPU) with zero server GPU cost.
  • Browser-safe sharding: Every .onnx_data weight file stays well below Chrome's 2 GB ArrayBuffer limit (~3.3 GB total download, cached in the browser after first load).
  • Numerically stable q4: Uses INT4 weights (MatMulNBits, block size 32) with FP32 activations — avoiding Gemma 4 FP16 overflow while remaining compatible with GPUs that lack shader-f16.
  • Clean fine-tune: Trained on cleaned Q&A prose (no leading "Answer" headers, no broken .html links, no markdown backslash escapes).

Quick Start (@huggingface/transformers v4)

Browser (WebGPU)

import {
  AutoProcessor,
  Gemma4ForConditionalGeneration,
  TextStreamer,
} from "@huggingface/transformers";

const modelId = "Otozure/gemma4-e2b-bible-ONNX";

const processor = await AutoProcessor.from_pretrained(modelId);
const model = await Gemma4ForConditionalGeneration.from_pretrained(modelId, {
  dtype: "q4",
  device: "webgpu", // or "wasm"
});

const messages = [{ role: "user", content: "Is God male or female?" }];
const prompt = processor.apply_chat_template(messages, {
  add_generation_prompt: true,
});
const inputs = await processor(prompt);

await model.generate({
  ...inputs,
  max_new_tokens: 384,
  do_sample: true,
  temperature: 0.7,
  top_p: 0.9,
  top_k: 40,
  repetition_penalty: 1.1,
  streamer: new TextStreamer(processor.tokenizer, {
    skip_prompt: true,
    skip_special_tokens: true,
  }),
});

Node.js

npm install @huggingface/transformers@4
import { AutoProcessor, Gemma4ForConditionalGeneration } from "@huggingface/transformers";

const modelId = "Otozure/gemma4-e2b-bible-ONNX";
const processor = await AutoProcessor.from_pretrained(modelId);
const model = await Gemma4ForConditionalGeneration.from_pretrained(modelId, {
  dtype: "q4",
  device: "cpu",
});

const messages = [{ role: "user", content: "What does the Bible say about forgiveness?" }];
const prompt = processor.apply_chat_template(messages, { add_generation_prompt: true });
const inputs = await processor(prompt);

const outputs = await model.generate({
  ...inputs,
  max_new_tokens: 256,
  do_sample: true,
  temperature: 0.7,
  top_p: 0.9,
  top_k: 40,
  repetition_penalty: 1.1,
});

const reply = processor.batch_decode(
  outputs.slice(null, [inputs.input_ids.dims.at(-1), null]),
  { skip_special_tokens: true }
);
console.log(reply[0]);

ONNX Package Layout

Matches the exact multi-session contract of onnx-community/gemma-4-E2B-it-ONNX:

Component Description Approx. Size
onnx/decoder_model_merged_q4.onnx (+ _data) Fine-tuned 35-layer Gemma 4 text decoder (15 KV-cache layers with mixed 256/512 head dims + num_logits_to_keep) ~1.33 GB
onnx/embed_tokens_q4.onnx (+ _data) Base Gemma 4 E2B token & per-layer embeddings (inputs_embeds, per_layer_inputs) ~1.68 GB
onnx/vision_encoder_q4.onnx (+ _data) Base Gemma 4 E2B vision encoder (unchanged) ~107 MB
onnx/audio_encoder_q4.onnx (+ _data) Base Gemma 4 E2B audio encoder (unchanged) ~181 MB

Training & Export Details

  • Base model: unsloth/gemma-4-E2B-it (google/gemma-4-E2B-it)
  • Dataset: Otozure/gotquestionsdotorg (9,504 cleaned theology Q&A pairs)
  • Method: QLoRA via Unsloth (r=16, lora_alpha=16, lora_dropout=0, language attention + MLP layers only; vision/audio/embedding layers frozen)
  • Training configuration: max_seq_length=4096, packing=True, train_on_responses_only, 1 epoch, cosine LR schedule (lr=2e-4, warmup_steps=30, adamw_8bit)
  • Merge & ONNX conversion: Merged LoRA onto unquantized bfloat16 base weights (merge_and_unload), exported decoder_model_merged to ONNX opset 18 (attn_implementation="eager"), and quantized directly from FP32 → INT4 (MatMulNBitsQuantizer, block_size=32, symmetric, accuracy_level=4).

Intended Use, Limitations & Attribution

  • Intended use: Educational and research exploration of Christian theological Q&A and local browser-based LLM deployment.
  • Limitations: As a compact 4-bit quantized 2B-effective model, responses may occasionally paraphrase scripture inaccurately or miss theological nuance — always verify Bible references against primary scripture texts.
  • Attribution: Fine-tuning data originates from GotQuestions.org; this model is an independent community project and is not affiliated with or endorsed by GotQuestions Ministries.
  • License: Subject to the Gemma Terms of Use.
Downloads last month
7
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Otozure/gemma4-e2b-bible-ONNX

Adapter
(248)
this model

Dataset used to train Otozure/gemma4-e2b-bible-ONNX