jingyaogong
cc9629e5f4
[update] fix decoding, drop tests
2026-11-18 23:08:56 +08:00
jingyaogong
9f05da1c3d
Merge pull request #919 from Afloat16/fix/lora-merge-fp32
...
[fix] accumulate LoRA deltas before rounding merged weights
2026-11-18 22:57:11 +08:00
jingyaogong
eaa4b87f67
Merge pull request #912 from Afloat16/fix/generation-greedy-temperature
...
[fix] ignore sampling temperature for greedy generation
2026-11-18 22:56:56 +08:00
Afloat
767dd65859
[fix] accept boolean padding masks in manual attention
2026-11-18 17:40:59 +08:00
Afloat
5f69faf966
[fix] ignore sampling temperature for greedy generation
2026-11-18 17:40:54 +08:00
Afloat
5240cc8133
[fix] accumulate LoRA deltas before rounding merged weights
2026-11-18 17:40:45 +08:00
jingyaogong
2de2308d71
[update] trim merged pr leftovers
2026-11-18 14:08:54 +08:00
uphomer
9012e5e0ef
[fix] LoRA: add alpha/rank scaling with backward-compatible persistence
...
当前 LoRA 前向为 B(A(x)),没有标准 LoRA 的 alpha/r 缩放(等价 alpha=r)。
#894 合入 --lora_rank 后 rank 可配,但有效更新尺度仍与 rank 耦合
(实测同 lr 下初始 ||dL/dB||: rank 4/8/16/32 = 0.0274/0.0374/0.0557/0.0846,约 sqrt(r)),
rank 消融与超参迁移受影响。
修复:
- LoRA(..., lora_alpha=None):scaling = (rank if lora_alpha is None else lora_alpha) / rank
- forward 乘 scaling;scaling 注册为 buffer 随 state_dict 持久化
- save_lora:权重存 half、buffer 存 float32
- load_lora:strict=False,旧 checkpoint 缺 scaling 时默认 1
- merge_lora:合并时乘 scaling
- train_lora.py:新增 --lora_alpha(默认 None = rank)
验证:
- 默认 alpha=None:scaling=1,输出与旧实现逐位一致
- alpha=2r:低秩分支输出 2x
- save/load:scaling 保留;float32 原值逐位一致;half 保存(原有行为)最大差异 1.6e-5
- 旧 checkpoint(无 scaling):可加载,scaling=1
- merge 一致性(alpha=2r):max diff 1.3e-4(half 精度)
- 完整模型:rank=8 时 LoRA 0.197M,16 个 scaling buffer
- 真实 train_lora 冒烟(rank=8, alpha=16):约 2780 步 loss 有限
2026-11-03 20:19:45 +08:00
jingyaogong
1e6e909f88
[update] trim redundant comments
2026-09-20 20:33:40 +08:00
Linxiushen
ba10c4d17b
[fix] float16 下 attention mask 的 -1e9 溢出成 -inf,导致整条序列输出 NaN
...
Attention.forward 的手写 softmax 分支(flash SDPA 关闭时走这里):
scores = (xq @ xk.transpose(-2, -1)) / math.sqrt(self.head_dim)
...
if attention_mask is not None: scores += (1.0 - mask) * -1e9
output = ... F.softmax(scores.float(), dim=-1) ...
scores 的 dtype 跟随 xq/xk。float16 模型下它是 float16,而
torch.finfo(torch.float16).min ≈ -65504,把 -1e9 累加进去会饱和成 -inf
(不是一个很大的有限负数)。当某个 query 在因果范围内可见的 key 全被 mask
掉时(左 padding 必然出现),softmax 整行 = NaN,并在下一层通过 K/V 投影
扩散到同序列里 mask=1 的有效 token 上。
.float() 加在 softmax 那一刻已经太晚——溢出发生在它之前。
修复:把 float32 提升提前到加 mask 之前,两处共 2 行。
fp32/bf16 路径数值等价(fp32 下原来的 .float() 本就是 no-op)。
2026-09-20 11:50:28 +08:00
jingyaogong
cc312c1cc6
[fix] unify Ctrl+C handling
2026-09-18 16:33:09 +08:00
jingyaogong
b63a9565e3
[fix] restore top-1 router gradient #858
2026-09-18 15:28:50 +08:00
basil-k-aji-dev
1c876435ef
[fix] keep the MoE router trainable at num_experts_per_tok=1
...
Normalising a single top-k weight by its own sum gives exactly 1.0 for every
token, so the gate leaves the graph entirely: topk_idx is a discrete index and
the weight is now a constant, which leaves the LM loss no differentiable path
to the router. It then trains on aux_loss alone, whose optimum is a uniform
distribution, and the experts never specialise.
Measured on MOEFeedForward with router_aux_loss_coef=0, so only the LM path can
contribute a gradient:
num_experts_per_tok=1, norm_topk_prob=True 7.02e-10 <- current default
num_experts_per_tok=1, norm_topk_prob=False 1.02e-02
num_experts_per_tok=2, norm_topk_prob=True 1.67e-02
Only normalise when there is more than one weight to normalise.
Note this changes the forward pass for existing num_experts_per_tok=1 MoE
checkpoints: the expert output was scaled by a constant 1.0 and is now scaled
by the gate probability.
Closes #858 .
2026-09-17 21:31:41 +05:30
jingyaogong
4a68da72d5
[fix] lora dims
2026-05-31 13:38:51 +08:00
jingyaogong
dddedc6881
[fix] repetition_penalty
2026-05-07 19:08:52 +08:00
jingyaogong
1718e9a44d
[fix] transformers-5.x
2026-04-19 23:48:54 +08:00
jingyaogong
5704766352
[update] tie embedding
2026-04-19 21:57:28 +08:00
jingyaogong
2ab6455d9d
[update] open causal
2026-04-02 15:28:58 +08:00
jingyaogong
101d7df2da
[update] minimind-3
2026-03-25 23:57:45 +08:00
jingyaogong
c090b69c4d
[update] align loss
2026-01-15 00:56:32 +08:00
jingyaogong
e119db8478
[fix] compile unpack
2026-01-14 20:13:32 +08:00
jingyaogong
1279a61681
[update] prompt prefill
2026-01-13 17:46:54 +08:00
jingyaogong
9d898576ac
[update] aux loss
2026-01-01 22:41:46 +08:00
jingyaogong
c65335b56f
[fix] experts unused
2025-12-31 21:47:04 +08:00
jingyaogong
a9c56b20e9
[fix] lora weight
2025-12-22 21:27:29 +08:00
whitesword
3a18fdd666
Fix: support loading DDP-saved LoRA weights for inference
2025-12-22 20:50:25 +08:00
jingyaogong
5129f0e2a2
[fix] dtype & lr
2025-12-09 13:01:38 +08:00
jingyaogong
ecd1ae1563
[fix] reduce aux_loss_alpha
2025-12-05 23:08:29 +08:00
jingyaogong
151fdf7e76
[feat] update yarn
2025-12-01 16:15:05 +08:00
jingyaogong
6b86ea399a
[feat] release memory
2025-11-27 19:39:49 +08:00
jingyaogong
f5374dc87f
[fix] model attn_mask
2025-11-19 22:26:53 +08:00
jingyaogong
a044578d73
[fix] update model
2025-11-18 13:07:20 +08:00
yuyu5333
7d02ce673c
fix: attn_forwad when is_causal=True assert attn_mask is None
2025-11-18 03:17:17 +00:00
jingyaogong
4014e62cdf
[fix] restore
2025-10-23 19:00:06 +08:00
jingyaogong
557bcc018d
[fix] issue-431
2025-10-23 18:56:30 +08:00
jingyaogong
4e35fb9da8
[fix] update model
2025-10-17 00:09:32 +08:00
jingyaogong
5ffde04b7c
update lora
2025-04-27 15:45:06 +08:00
jingyaogong
29454c31af
fix bugs
2025-04-27 09:56:49 +08:00
jingyaogong
274483cb1b
250426
2025-04-26 10:07:55 +08:00
jingyaogong
a62faf34bd
250426
2025-04-26 10:05:47 +08:00
jingyaogong
d9453ed9a3
update moe note
2025-04-09 17:38:31 +08:00
jingyaogong
4a7c1c49e8
update rlaif
2025-04-05 16:06:08 +08:00
jingyaogong
9e67798397
update generate
2025-04-05 15:53:55 +08:00
jingyaogong
399d526fbd
add hidden state
2025-04-05 14:39:56 +08:00
jingyaogong
ed01c5d84a
update inference
2025-04-05 12:03:04 +08:00
jingyaogong
bf81fd5f5e
rmsnorm float convert
2025-04-01 16:03:44 +08:00
jingyaogong
e369b33265
fix chat mask bug
2025-04-01 13:44:55 +08:00
jingyaogong
258507ff89
delete __pycache__
2025-04-01 11:51:54 +08:00
gongjy
844e79148c
update generate args
2025-02-15 23:56:09 +08:00
gongjy
19b388cd87
update generate args
2025-02-15 23:55:10 +08:00