FP16 is slower than FP32 on CPU due to lack of native FP16 compute. Use FP16 for GPU only.
Accuracy vs FP32
Variant
Cosine similarity
Top-1 match
Decode divergence
FP16
1.000000
Yes
0%
INT8
0.945775
Yes
80%
INT4
0.982727
Yes
97%
FP16 is near-lossless. INT8/INT4 show greedy decode divergence due to autoregressive error amplification, but with temperature sampling the quality difference is usually acceptable.
1import{ pipeline }from"@huggingface/transformers";23const generator =awaitpipeline(4"text-generation",5"varsan-g/danskgpt-tiny-chat-onnx",6{dtype:"int8"}7);89const messages =[10{role:"user",content:"Fortæl mig om dansk historie."},11];1213const result =awaitgenerator(messages,{14max_new_tokens:200,15temperature:0.7,16do_sample:true,17});1819console.log(result[0].generated_text.at(-1).content);
Streaming with TextStreamer
javascript
1import{AutoTokenizer,AutoModelForCausalLM,TextStreamer}from"@huggingface/transformers";23const tokenizer =awaitAutoTokenizer.from_pretrained("varsan-g/danskgpt-tiny-chat-onnx");4const model =awaitAutoModelForCausalLM.from_pretrained("varsan-g/danskgpt-tiny-chat-onnx",{5dtype:"int8",6});78const messages =[{role:"user",content:"Hvad er Danmark?"}];9const inputs = tokenizer.apply_chat_template(messages,{10add_generation_prompt:true,11return_dict:true,12});1314const streamer =newTextStreamer(tokenizer,{15skip_prompt:true,16skip_special_tokens:true,17callback_function:(text)=> process.stdout.write(text),18});1920await model.generate({...inputs,max_new_tokens:200,do_sample:true,temperature:0.7, streamer });
Note: This is a 1B parameter model. INT8 is ~1.1 GB which will take some time to download on first load (cached in browser afterward). For faster browser experiences, consider smaller models from the onnx-community.
Tokenizer note (Python): This model uses a SentencePiece .model file. You must pass use_fast=False to AutoTokenizer.from_pretrained() in Python, otherwise it may fail trying to parse the tokenizer as tiktoken. The JavaScript libraries use tokenizer.json and work without this workaround.
Changes from Original
This repository contains a format conversion of mhenrichsen/danskgpt-tiny-chat by mhenrichsen. The model weights have been converted from PyTorch (safetensors) to ONNX format, and quantized variants (FP16, INT8, INT4) have been produced. No fine-tuning or architectural modifications were made.
License
This model is distributed under the Apache License 2.0, the same license as the original model. See the LICENSE file in this repository for the full license text.