MNN-Pocket-0.3B

taobao-mnn/MNN-Pocket-0.3B

作者
taobao-mnn
任务
文本生成
下载量
676
点赞数
32
趋势分
32
许可证
apache-2.0
收录时间
2026/11/8

library_name: transformers license: apache-2.0 language:

  • en
  • zh pipeline_tag: text-generation tags:
  • mnn
  • mnn-pocket
  • on-device
  • edge
  • qwen3
  • int4 base_model: taobao-mnn/MNN-Pocket-0.3B-Base

MNN-Pocket-0.3B

MNN-Pocket is a family of compact language models co-designed with the MNN inference stack for on-device deployment. MNN-Pocket-0.3B is the general-purpose, instruction-tuned member of the family.

  • Tiny footprint: ~300M parameters; the INT4 (W4A16) QAT MNN build occupies only 173 MB.
  • Fast edge inference: up to 466 tokens/s decode on iPad Pro M5 (Metal), above the 200 tok/s real-time target.
  • Context length: up to 32K tokens.
  • Balanced bilingual capability: best average (50.00) across 11 zh/en benchmarks among ~300M models, surpassing several ~500M baselines.

Demo

Model Details

ModelParametersDescription
MNN-Pocket-0.3B-Base300MPre-trained base model for fine-tuning
MNN-Pocket-0.3B-SFT300MSupervised fine-tuning (SFT) checkpoint, intermediate stage for research and ablation
MNN-Pocket-0.3B300MGeneral-purpose instruction-tuned model
MNN-Pocket-0.3B-GGUF300MGGUF for llama.cpp: F16 / Q8_0 from the BF16 checkpoint, Q4_1 from the QAT checkpoint
MNN-Pocket-0.3B-MNN300MINT4 (W4A16) QAT MNN build for on-device deployment
MNN-Pocket-0.3B-Dec300MNon-autoregressive decision model: LoRA adapter + pointer head, answers every question in one forward pass

Architecture:

  • Parameters: ~300M
  • Layers: 28
  • Hidden size: 896
  • Attention: 14 heads, GQA with 2 KV heads, head_dim 64
  • FFN intermediate: 2560 (SiLU)
  • Context: 40,960 positions (32K supported in deployment)
  • Vocabulary: 65,536
  • Embeddings: tied input/output
  • Precision: bfloat16 native; INT4 W4A16 (MNN build)
  • Languages: Chinese, English

MNN-Pocket-0.3B is intended for on-device assistants, data extraction, and lightweight agentic pipelines. Like other sub-billion-parameter models, it is not recommended for reasoning-heavy workloads such as advanced mathematics or long-horizon code generation.

Chat Template

MNN-Pocket uses a ChatML-style conversation format. The exact template (including the im_start / im_end control tokens) ships in this repo as chat_template.jinja; prefer tokenizer.apply_chat_template() so formatting stays correct automatically. Schematic:

[IM_START]system
You are a helpful assistant.[IM_END]
[IM_START]user
Hello![IM_END]
[IM_START]assistant
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("taobao-mnn/MNN-Pocket-0.3B")
text = tok.apply_chat_template(
    [{"role": "system", "content": "You are a helpful assistant."},
     {"role": "user", "content": "Hello!"}],
    add_generation_prompt=True, tokenize=False)

Inference

MNN-Pocket is optimized for the MNN runtime but also runs in Transformers and llama.cpp.

On-device with MNN: the INT4 (W4A16, block 64) QAT build is published as MNN-Pocket-0.3B-MNN.

For other precisions, export from the safetensors in this repo with llmexport:

# Download the MNN source
git clone https://github.com/alibaba/MNN.git

# Export to MNN (INT4, block 64)
cd MNN/transformers/llm/export
python llmexport.py --path /path/to/MNN-Pocket-0.3B --export mnn --quant_bit 4 --quant_block 64

Build flags, config.json options and llmexport parameters are in the MNN-LLM doc.

With the MNN weights in hand — the published INT4 build or your own export — build the runtime and run it:

# Download the MNN source (only needed if you have not cloned it yet)
git clone https://github.com/alibaba/MNN.git

# Build
cd MNN
mkdir build && cd build
cmake .. -DMNN_LOW_MEMORY=true -DMNN_BUILD_LLM=true -DMNN_SUPPORT_TRANSFORMER_FUSE=true
make -j

# Run
./llm_demo /path/to/MNN-Pocket-0.3B-MNN/config.json prompt.txt

Transformers:

from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "taobao-mnn/MNN-Pocket-0.3B"
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", dtype="bfloat16")
tokenizer = AutoTokenizer.from_pretrained(model_id)

messages = [{"role": "user", "content": "What is MNN?"}]
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True,
                                       return_tensors="pt", tokenize=True, return_dict=True).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512, do_sample=True,
                         temperature=0.8, top_p=0.8, top_k=20)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))

llama.cpp: see MNN-Pocket-0.3B-GGUF.

Performance

Post-trained MNN-Pocket-0.3B vs. same-size and larger open models (higher is better). Full protocol in the tech report.

BenchmarkMNN-Pocket-0.3B-INT4Gemma-3-270MERNIE-4.5-0.3BLFM2.5-350MSmolLM2-360MHunyuan-0.5BMiniCPM4-0.5BQwen3-0.6B
Average50.0049.596.4231.9931.2818.4331.2246.8144.28
C-Eval38.8640.276.8432.1732.1023.7735.2967.9844.06
CMMLU40.1139.654.9433.9131.6524.8735.6966.0444.50
MMLU-Redux44.0043.4013.5832.6841.0124.1736.2952.8551.63
BBH47.3846.638.0931.0726.0327.7454.6547.6141.94
IFEval73.2074.1220.1544.9272.0932.1624.5852.1356.93
IFEval-zh74.5972.4917.0232.8744.0625.6425.8730.3050.35
GSM8K54.3652.840.0031.2433.6611.6036.0142.4645.49
MGSM-zh51.2048.800.0025.2018.003.6034.8037.6040.00
MATH50035.4035.400.0021.4014.804.6035.8023.0045.20
HumanEval53.6653.660.0038.4114.630.0014.6348.1736.59
MBPP37.2038.200.0028.0016.0024.609.8046.8030.40

The INT4 (W4A16) QAT build loses only 0.41 points on average (49.59 vs 50.00), confirming quantization largely preserves quality while cutting the footprint to ~173 MB.

On-Device Speed

Prefill / decode throughput at 512-token context with the INT4 build:

DeviceBackendPrefill (tok/s)Decode (tok/s)
iPad Pro M5Metal8,721466
iPad Pro M5CPU2,228231
Snapdragon 8 Gen 5OpenCL3,403138
Snapdragon 8 Gen 5CPU930251

License

Released under the Apache License 2.0. See LICENSE.txt.

Citation

@misc{mnn2026pocket,
  title  = {MNN-Pocket-0.3B Technical Report},
  author = {{MNN Team}},
  year   = {2026}
}

内容来源:Hugging Face 模型卡

在 Hugging Face 查看