Otozure/gotquestionsdotorg
Viewer • Updated • 9.5k • 1
How to use Otozure/gemma4-e2b-bible-ONNX with Transformers.js:
// npm i @huggingface/transformers
import { pipeline } from '@huggingface/transformers';
// Allocate pipeline
const pipe = await pipeline('text-generation', 'Otozure/gemma4-e2b-bible-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).
.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).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."Answer" headers, no broken .html links, no markdown backslash escapes).@huggingface/transformers v4)
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,
}),
});
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]);
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 |
unsloth/gemma-4-E2B-it (google/gemma-4-E2B-it)r=16, lora_alpha=16, lora_dropout=0, language attention + MLP layers only; vision/audio/embedding layers frozen)max_seq_length=4096, packing=True, train_on_responses_only, 1 epoch, cosine LR schedule (lr=2e-4, warmup_steps=30, adamw_8bit)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).