🎲 random-number-gguf

只会随机吐一个数字的 GGUF 模型。 无论输入什么、上下文多长、怎么注入指令,它都只输出指定范围内的均匀随机数字,然后停止。

零训练:1 层 llama(该层全 0),权重手写;无数据集、无反向传播。全模型约 59 万参数,最小档仅 249 KB。

版本 取值 参数 F16 Q2_K
random-binary 0/1 591,616 1.16 MB 249 KB
random-digit 0~9 591,616 1.16 MB 249 KB
random-num100 0~100 638,208 1.23 MB 277 KB

每版 6 档量化:F16 / Q8_0 / Q4_K_M(推荐)/ Q4_K_S / Q3_K_M / Q2_K。根目录 random-binary.gguf / random-digit.gguf / random-num100.gguf 为一键版,等于 Q2_K。

原理

  1. 层是空的:attention、FFN 权重全 0,残差使每层输出等于输入。
  2. 输入被抹平:embedding 只有“数字 token”和“所有非数字 token”两种状态;隐藏状态只取决于“上一个 token 是不是数字”。
  3. 两个状态:状态 A 下 N 个数字 logit 完全相等,softmax 均匀,采样器随机选一个;刚输出数字后进入状态 B,只有 EOS 为正 logit,立即停止。

“随机”来自均匀 softmax + 采样器随机性,不是学出来的。范围由结构钉死:只有 N 个数字 token 能拿正 logit,其余 token(含 EOS)在第一个位置都是 -1597.96,不会越界。推导见 docs/how-it-works.md。

快速开始

Ollama

ollama create random-digit -f Modelfiles/Modelfile.digit
ollama run random-digit "随便说点什么"       # → 7
ollama run random-num100 "今天天气怎么样"     # → 42

Modelfile:Modelfile.binary / Modelfile.digit / Modelfile.num100。换量化档改 FROM 行文件名。

LM Studio / 其它前端

拖入 .gguf 后必须改采样参数:

参数 必须值 原因
top_p 1.0 小于 1 会砍尾部,某些数字永远抽不到
top_k ≥ 取值个数(2/10/101) 默认 40 会让 0~100 只剩约 36 个值可能中
temperature 1.0 保持 N 个选项等高
repeat_penalty 1.0 避免压低刚输出的数
presence/frequency_penalty 0 同上

llama.cpp

# 对话模式(推荐)
llama-cli -m gguf/random-digit-Q4_K_M.gguf -p "你好" -n 4 \
          --temp 1.0 --top-p 1.0 --top-k 10 -st

# 纯补全模式:必须加 -no-cnv
llama-completion -m gguf/random-num100-Q2_K.gguf -p "任意" -n 1 \
                 --temp 1.0 --top-p 1.0 --top-k 101 -no-cnv -st

实测 random-num100-Q2_K:4 线程纯 CPU、ctx 8192,峰值内存 30.9 MB,约 240 tok/s。
注意:llama.cpp b11588 的 llama-completion 不加 -no-cnv 可能崩溃;llama-cli -st 不受影响。

三个坑

  1. top_p 必须 1.0:N 个选项等概率时,top_p<1 必然砍掉尾部。实测 Ollama 默认 top_p=0.9, top_k=40 下,random-digit 300 次里 0 一次没出现;random-num100 默认只露出约 37 个取值。改 top_p=1.0、top_k≥N 后通过均匀性检验。
  2. 空 prompt 无输出:Ollama 对 prompt="" 返回空字符串,与模型无关。给空格或任意字符即可。
  3. 纯补全模式输入以数字结尾会直接停:模型靠“上一个 token 是数字”触发停止。绕过 chat 模板喂 "5" 会输出空;补空格或换说法。对话模式不受影响,因为 GGUF chat template 是 {{ bos_token }},正文在模板层被丢弃。

验证

  • 18/18 个 GGUF 文件通过:全部产出合法取值、长度恒为 1、χ² 检验 p ≥ 0.01。
  • 3 个版本共 900 次默认采样参数测试:越界 0 次,空输出 0 次。默认参数下能抽到的取值数会被 top_p/top_k 砍掉一部分,但不可能抽到范围外。
  • random-digit 对中文、英文、emoji、300 字重复、指令注入、以数字结尾、纯空白等 9 类输入各 400 次:合计 3200/3200 合法单数字,分布通过;唯一已知限制是 Ollama 空 prompt 返回空。

文件与生成

量化文件:

gguf/random-{binary,digit,num100}-{F16,Q8_0,Q4_K_M,Q4_K_S,Q3_K_M,Q2_K}.gguf

根目录一键版为对应 Q2_K。完整 SHA-256 见仓库文件清单。

生成器只依赖 numpy:

python tools/make_random_gguf.py out.gguf --family 09      # 0~9
python tools/make_random_gguf.py out.gguf --family 01      # 0/1
python tools/make_random_gguf.py out.gguf --family 0100    # 0~100
python tools/make_random_gguf.py dice.gguf --numbers "1,2,3,4,5,6"
python tools/make_random_gguf.py --inspect out.gguf

生成时自动自测:数字 token logit 是否严格相等、EOS 是否为第二状态 argmax、非数字 token 是否落入同一状态。

许可

MIT。随便玩。

Downloads last month
425
GGUF
Model size
592k params
Architecture
llama
Hardware compatibility
Log In to add your hardware

2-bit

3-bit

4-bit

8-bit

16-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support