Chunked DFlash loss path flattens prev_token_ids, breaking DSpark subclass heads

未关闭
#3 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
python, pytorch

调研方向

先阅读 angelspec/models/dflash.py 中的 _forward_chunked_decay 和 chunk gate,然后比较 angelspec/models/dspark.py 与 angelspec/models/draft/dspark.py 中的 hook 实现。使用仅 Markov 的 DSpark 配置并设置 confidence_head_alpha=0,在 ANGELSPEC_DFLASH_LOSS_CHUNK > 0 时复现 decay objective。完成的标准是 chunked path 不再崩溃,并在适用时保留 pos_alpha.smooth_loss() regularizer。

由索引模型根据 Issue 内容生成。

描述

In _forward_chunked_decay, prev_token_ids is flattened to 2-D before being passed to the _compute_draft_logits hook:

https://github.com/Tencent/AngelSpec/blob/main/angelspec/models/dflash.py#L1089-L1094

prev_chunk = prev_token_ids[:, start:end].reshape(bsz, nb * bs)   # 2-D
logits_chunk = self._compute_draft_logits(dh_chunk, lm_head_weight, prev_chunk, nb)

But DSparkModel._compute_draft_logits (angelspec/models/dspark.py) forwards prev_token_ids to markov_head.apply_block_logits(token_ids=...), which expects [B, n_blocks, block_size] (angelspec/models/draft/dspark.py). With a 2-D input, compute_step_bias produces a [bsz, nb*bs, V] bias that is added to [bsz, nb, bs, V] logits — a RuntimeError whenever nb > 1 (and a silently wrong broadcast followed by a reshape crash when nb == 1, bsz > 1).

The gate that is supposed to keep subclass heads off the chunked path only checks _extra_distill_needed():

https://github.com/Tencent/AngelSpec/blob/main/angelspec/models/dflash.py#L754-L761

For DSpark that returns True only when a confidence head is active, so a DSpark model with only a markov_head (or confidence_head_alpha=0) plus ANGELSPEC_DFLASH_LOSS_CHUNK > 0 and the decay objective takes the chunked path and crashes. This contradicts the stated intent in _dflash_loss_chunk's docstring ("dpace / distillation / subclass heads keep the single full-vocab projection").

A secondary issue on the same path: _forward_chunked_decay never calls _compute_extra_loss, so the position-adaptive-alpha smoothness regularizer (pos_alpha.smooth_loss()) is silently dropped for any DSpark config that reaches the chunked path without crashing.

Possible fixes: extend the chunk gate to exclude models that override _compute_draft_logits / _compute_extra_loss, or pass prev_token_ids as [B, nb, bs] and make the hooks shape-consistent.

主要语言
Python
星标
460
派生
40
平均合并
1 小时 4 分钟
30 天内合并 PR
4

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Tencent/AngelSpec 的其他 Issue

查看 Tencent/AngelSpec 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。