Skip to content

[4/4] Support Falconer packed inputs and loss masks - #2880

Draft
askliar wants to merge 4 commits into
NVIDIA:mainfrom
askliar:askliar/falconer-packed-inputs-2826
Draft

askliar wants to merge 4 commits into
NVIDIA:mainfrom
askliar:askliar/falconer-packed-inputs-2826

Conversation

@askliar

@askliar askliar commented Oct 19, 2026

Copy link
Copy Markdown

What does this PR do?

Type of change: New feature.

Fourth PR in the stack. Merge #2692, then #2824, then #2826, then this PR.

This draft targets main because the parent branch exists only in another fork.
The first three commits belong to the parent PRs.
Review the additional changes in this comparison.
The branch needs a rebase after #2826 merges.

Falconer stores pre-tokenized conversations in safetensors shards with token IDs, binary loss masks, and sample offsets.
The packed-data path in #2826 reads Hugging Face datasets and does not preserve a separate loss-mask column.

This PR extends data.packed_data_path to read Falconer shards and preserve supplied loss masks.
The same source can supply online training or streaming hidden-state capture.
Existing Hugging Face packed datasets remain supported.

Summary

packed_data_path
  -> Falconer shard reader or Hugging Face dataset
  -> online packed batch or streaming hidden-state capture
  -> aligned token IDs, labels, padding mask, and loss mask

Usage

data:
  packed_data_path: /path/to/falconer/dataset

For streaming training, also set the serving endpoint and model name:

data:
  packed_data_path: /path/to/falconer/dataset
  streaming_server_url: http://server:8000
  streaming_model_name: target-model

Each shard contains flat input_ids and loss_mask tensors.
The offsets tensor contains one more entry than the sample count.
Each adjacent offset pair selects one sample.
A Falconer manifest controls shard order when present.
Mask value 1 enables supervision; value 0 excludes the token from supervision.

Testing

  • Data loading and streaming unit tests: 37 passed.
  • Packed-input model tests: 10 passed; 66 unrelated tests were deselected.
  • Runtime: Python 3.12.3, Torch 2.13.0+cu130, Transformers 5.17.0, Safetensors 0.8.0, and Datasets 5.0.1.
  • Tests ran on an OCI-JHB CPU allocation with offline Hugging Face access.
  • All applicable pinned pre-commit checks passed, including Ruff, mypy, Bandit, license checks, and Markdown checks.
  • Independent read-only review found no actionable defects.

The tests replace the streaming fetch operation.
They do not verify vLLM, NIXL, RDMA, distributed training, full-model quality, or representative dataset performance.

Evidence

Merge Danger

Door: two-way. Reverting the commit restores the parent data paths without modifying datasets.

Blast Radius: training-data loading and batch creation for packed inputs.

Before your PR is "Ready for review"

  • Is this change backward compatible?: Yes. Existing Hugging Face packed inputs remain supported, and legacy streaming retains its label alignment.
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md?: No new dependencies.
  • Did you write any new necessary tests?: Yes; the focused tests passed.
  • Did you update CHANGELOG.rst?: Yes.
  • Did you get Claude approval on this PR?: No.

Additional Information

Parent: #2826

Prepared against parent head 6f692296abc82c2f1d646f164f61d2491422ff45.

Relative to #2826, this follow-up adds 238 production source lines across 11 changed files, including tests and documentation.

yeyu-nvidia and others added 4 commits October 14, 2026 11:00
The base forward ran under an unconditional torch.no_grad(), so
dflash_freeze_base_model=False was silently inert. convert() honours the flag
on the parameters -- requires_grad stays True -- but with no autograd graph
built, nothing ever reaches them. The base sits at its initial weights for the
entire run while every surface reports it as trainable.

It is a quiet failure. There is no error and no warning; the only symptom is a
base-model loss that does not move, which is easy to read as a bad learning
rate or a hard dataset. It surfaced here as a co-training experiment whose
"unfrozen" arm held a perfectly flat cross-entropy while its control arm
descended normally -- which looked like a result about co-training rather than
a bug.

The context is now chosen from the flag. The other no_grad blocks in this file
are deliberate and untouched: the D-PACE weighting is detached by design (paper
Eq.9) and the accuracy computation is a metric.

Training with the base unfrozen now also costs the activation memory that
implies, which is the expected consequence of the flag doing what it says.

Testing: two tests in tests/unit/torch/speculative/plugins/test_hf_dflash.py --
the frozen default builds no graph, and the unfrozen case builds one and
receives a non-zero gradient on the base parameters after backward. Verified
the pair catches the bug: with the fix 2 passed; with the base forward reverted
to the unconditional no_grad, the unfrozen test fails on the grad_fn assertion
and the frozen one still passes. Run on aarch64 with torch 2.13 and
transformers 5.12.1. pre-commit clean on all three files.

Signed-off-by: Ye Yu <[email protected]>
With dflash_freeze_base_model=False the only gradient reaching the base comes
from the draft objective. Nothing holds it to language modelling, so the base
drifts toward whatever is easiest to draft rather than toward predicting text --
which makes "co-training" a misnomer: it is really optimising a base for
draftability and watching it degrade.

dflash_base_lm_loss_alpha adds a cross-entropy on the base's own next-token
prediction, weighted and added to the draft loss. Default 0.0, so the existing
objective is unchanged for everyone not asking for it.

Both preconditions are checked rather than silently ignored, because a term that
quietly contributes nothing is the failure mode this area already had: a
non-zero weight on a frozen base raises at convert time (no graph, no gradient),
and a missing labels tensor raises at forward rather than skipping the anchor.

The causal shift is done here rather than assumed: DFlash's data module builds
labels unshifted (shift_labels=not is_dflash).

Testing: 6 tests in tests/unit/torch/speculative/plugins/test_hf_dflash.py --
the default leaves the loss untouched, a non-zero weight both changes the loss
and delivers non-zero gradient to base parameters, a frozen base is refused at
convert, and missing labels are refused at forward. pre-commit clean.

Signed-off-by: Ye Yu <[email protected]>
The online data path renders conversations through a chat template, so a
pretraining corpus cannot be expressed at all: raw documents have no
conversation structure, and wrapping them in pseudo-turns would insert chat
tokens into the text and, with answer_only_loss, mask most of it away. That left
co-training a base alongside a drafter reachable only on chat data.

data.packed_data_path takes a datasets.save_to_disk directory of fixed-length
pre-tokenized blocks and derives the new "packed" mode the same way the existing
modes are derived -- from which data-source field is set, never from an incoming
mode value. Packing deliberately stays outside this library: it is expensive, it
has to be byte-identical across runs being compared, and tokenizer policy is not
this library's to own.

The collator is a stack, since the blocks are already fixed-length and
tokenized. labels defaults to input_ids because for causal LM the shift belongs
to the loss, and the DFlash path shifts there (shift_labels=not is_dflash).

main.py previously derived use_offline_training as "mode != online", which would
have classified packed as offline and loaded the fake base meant for pre-dumped
hidden states -- training against a model that is not there, with nothing saying
so. packed is an online path with a different data source and is now treated as
one.

Testing: 11 tests in tests/unit/torch/speculative/plugins/test_hf_dflash.py --
mode derivation and its ambiguity check, the collator stacking blocks,
defaulting labels, honouring explicit labels, truncating to train_len, rejecting
rows without input_ids, and a guard that packed is not classified as offline.
pre-commit clean on all six files.

Signed-off-by: Ye Yu <[email protected]>
Extend the packed data path from PR NVIDIA#2826 to read Falconer safetensors and preserve binary supervision masks in online and streaming training.

Signed-off-by: Andrii Skliar <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants