FilesLast commitLast update
README

模型目录 · LH-Tech-AI/Quark-v2-0.5M

下载日期:2026-09-16 | 来源仓库 commit:7a30cd277348416659e94d5937d699d72e34afac

下载渠道说明

huggingface.co 在本机直连超时(curl 返回 000),必须走镜像:

curl -L --noproxy '*' \
  "https://hf-mirror.com/LH-Tech-AI/Quark-v2-0.5M/resolve/main/<文件名>"

两个坑:

  • 必须加 --noproxy '*':环境里设了 HTTP_PROXY=http://127.0.0.1:54572(沙箱本地代理), 走代理时 CONNECT tunnel failed, response 502。绕开代理才能通。
  • hf-mirror 的 TTFB 很慢(首字节可达 90 秒),--max-time 要给到 300 秒,别用 30 秒。

文件清单

Quark-v2-0.5M/ 是仓库的完整镜像,共 11 个文件、1,904,432 字节。

文件 字节 说明
model.safetensors 1,866,072 权重,fp32,39 个张量
tokenizer.json 20,350 BPE 词表 + 239 条 merges
train.py 5,121 原始训练脚本
training_args.bin 5,137 训练超参(pickle)
README.md 3,454 官方模型卡
.gitattributes 1,519
inference.py 927 官方推理示例
config.json 714 架构配置
train_tokenizer.py 703 分词器训练脚本
tokenizer_config.json 220
generation_config.json 215

完整性校验(已通过)

model.safetensors  size = 1,866,072   ✓ 与官方一致
sha256 = 3fce3f379b5c485d25f72364d10fd8d9fe22a1f38e244531391e77272cb79404
       = 官方 LFS oid                                          ✓ 逐位一致
总参数量 = 465,504                                          ✓ 与模型卡一致

config.json 关键项(本文件是权威,覆盖此前所有推测)

{
  "architectures": ["LlamaForCausalLM"],
  "model_type": "llama",
  "dtype": "float32",
  "vocab_size": 500,
  "hidden_size": 96,
  "intermediate_size": 192,
  "num_hidden_layers": 4,
  "num_attention_heads": 4,
  "num_key_value_heads": 4,          // = heads,标准 MHA,无 GQA
  "head_dim": 24,                    // 显式声明,96/4
  "hidden_act": "silu",              // SwiGLU
  "attention_bias": false,           // 无 qkv bias
  "mlp_bias": false,                 // 无 mlp bias
  "tie_word_embeddings": false,      // ★ lm_head 独立
  "rms_norm_eps": 1e-06,
  "rope_parameters": { "rope_theta": 10000.0, "rope_type": "default" },
  "max_position_embeddings": 256,
  "bos_token_id": 0, "eos_token_id": 2, "pad_token_id": 1,
  "use_cache": false                 // ★ config 里是 false,但 generation_config 里是 true
}

此前基于参数量反推的三个结论全部得到实证:

  1. tie_word_embeddings: false —— lm_head 未绑定 ✓
  2. 每层 2 个 RMSNorm(input_layernorm + post_attention_layernorm)✓
  3. SwiGLU 三矩阵(gate/up/down)✓

use_cache 在 config 与 generation_config 里不一致(false vs true)。 对可视化项目无影响——KV Cache 由前端自己实现,不走 transformers 的缓存开关。 但若用 Python 做基准前向,注意显式传 use_cache=True 才能拿到 KV。

39 个张量(确切的权重键名)

lm_head.weight                                 [500, 96]
model.embed_tokens.weight                      [500, 96]
model.norm.weight                              [96]
model.layers.{0..3}.input_layernorm.weight      [96]
model.layers.{0..3}.post_attention_layernorm.weight [96]
model.layers.{0..3}.self_attn.q_proj.weight    [96, 96]
model.layers.{0..3}.self_attn.k_proj.weight    [96, 96]
model.layers.{0..3}.self_attn.v_proj.weight    [96, 96]
model.layers.{0..3}.self_attn.o_proj.weight    [96, 96]
model.layers.{0..3}.mlp.gate_proj.weight       [192, 96]
model.layers.{0..3}.mlp.up_proj.weight         [192, 96]
model.layers.{0..3}.mlp.down_proj.weight       [96, 192]

注意 down_proj 是 [96, 192]——行数 96、列数 192,与 gate/up 相反。 写 forward.js 时矩阵乘方向别搞反。safetensors 里的 shape 是 [out_features, in_features], 即 y = x @ W.T,而参考实现的 matMul(X, W) 是 X @ W, 所以权重从 safetensors 读出后需要转置才能直接套用参考的矩阵乘约定。

tokenizer 事实(与参考实现差异很大,必须改)

tokenizer.json 里 model.type = "BPE",vocab 大小 500,merges 239 条。 pre_tokenizer 为 ByteLevel(add_prefix_space: false)。

区间 内容
0–4 5 个特殊 token
5–98 94 个可打印 ASCII 字节(! ~ ~)
99–499 401 个合并 token(如 Ġthey → id 497)
id token
0 <s> (bos)
1 <pad>
2 </s> (eos)
3 <unk>
4 <mask>

三个必须改的地方(参考实现里是 EOS_ID = 1、<unk> = 0):

  1. eos 是 2,不是 1。参考实现 const EOS_ID = 1(L286)需要改成 2。
  2. unk 是 3,不是 0。参考实现用 logits[0] = -Infinity 屏蔽 <unk>(L615、L620、L627), 在 Quark 里要改为屏蔽 id 3。同时确认是否也要屏蔽 <pad>(1) / <mask>(4)。
  3. 合并 token 用 Ġ 表示空格(如 Ġthey、Ġwhe)。前端显示 token 时要把 Ġ 渲染成 ␣ 或空格,否则界面里会出现一片乱码字符。

复现下载

mkdir -p models/Quark-v2-0.5M && cd models/Quark-v2-0.5M
for f in config.json generation_config.json tokenizer_config.json tokenizer.json \
         model.safetensors train.py train_tokenizer.py inference.py \
         README.md .gitattributes training_args.bin; do
  curl -L --noproxy '*' --retry 3 --max-time 300 -O \
    "https://hf-mirror.com/LH-Tech-AI/Quark-v2-0.5M/resolve/main/$f"
done