Skip to content

ExternalDraftConfig accepts tvd_ce weights that produce zero or infinite loss #3524

Open

Description

@fernandezbaptiste

Hullo folks,

I’m doing some research for Tessl Code Review and ran it against your repo. It flagged a potential issue, and I figured it made sense to share it with you:

ExternalDraftConfig(external_loss="tvd_ce", ...) accepts both a zero/zero weight pair and an infinite weight. The current _mix_ce then produces a zero objective or a non-finite loss.

Reproduction

ExternalDraftConfig(
    external_loss="tvd_ce",
    external_tvd_alpha=0.0,
    external_ce_alpha=0.0,
)  # accepted

ExternalDraftConfig(
    external_loss="tvd_ce",
    external_tvd_alpha=float("inf"),
    external_ce_alpha=0.1,
)  # also accepted

Both fields have ge=0.0, but neither a finiteness constraint nor a combined-positive-weight check.

Validation

I executed the current ExternalDraftConfig class using the actual current ModeloptBaseConfig and ModeloptField, with Pydantic 2.14.4 and PyTorch 2.15.0 on CPU. The two configurations above were accepted; a negative weight was rejected.

I also executed the current _mix_ce method with a small logits/target fixture and a controlled TVD scalar:

  • Weights 0/0: loss 0, zero logits gradient and zero TVD gradient.
  • Weights infinity/0.1: infinite loss and infinite TVD gradient.
  • Weights 0.9/0.1: finite loss and gradients.

No GPU or full training run was involved.

Expected behavior

For tvd_ce, reject non-finite weights and require at least one positive contribution. That would catch a configuration that silently disables the objective before starting training, while still allowing either individual term to be disabled.

Current source: implementation. The lead came from this earlier review finding, and I checked it against the current source.

Full transparency: I work at Tessl, and we've spotted that using Tessl Code Review - using repository-level context and specific review lenses that improve over time through feedback. That’s how this finding surfaced.

We’re just getting started and want to offer the tool free to open-source projects. If this is useful, happy to give you access.

Bap

Activity

  1. adimalkar commented on Nov 23, 2026

    @adimalkar

    Reproduced on main (3497c11): ExternalDraftConfig(external_loss="tvd_ce") accepts weights 0/0 and inf, and _mix_ce then returns a loss of exactly 0 with zero gradients, or an infinite loss with an infinite TVD gradient. I'd like to take this. The plan is allow_inf_nan=False on both weights, plus a validator that rejects 0/0 only when the objective is tvd_ce, so either term can still be turned off on its own. Tests go in tests/unit/torch/speculative/test_external_draft.py; PR to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions