Skip to content

Repeated "intermediate output already stored" warnings during gradient accumulation #2487

Description

@TheSabari07

Describe the bug

I noticed that when training with gradient accumulation (gradient_accumulation_steps=8), both the teacher and student's wrapped modules repeatedly emit the following warnings on nearly every step:

UserWarning: Teacher's Module `Qwen2ForCausalLM` already has an intermediate output stored.
This is expected when `DistillationModel.compute_kd_loss` is not called in eval mode.

UserWarning: Student's Module `DistillQwen2ForCausalLM` already has an intermediate output stored.
This is undesired behavior unless Activation Checkpointing is in use.

I may be misunderstanding the intended behavior here, so I wanted to ask whether these warnings are expected during normal gradient accumulation.

Impact: Nice to have / clarity issue. Training continues, but the warnings appear very frequently and make it difficult to distinguish them from potentially important training warnings.

In particular, the second warning mentions that the behavior is "undesired" unless Activation Checkpointing is being used. I would appreciate clarification on whether this indicates an actual correctness or memory issue in this configuration.

Steps/Code to reproduce bug

  1. Wrap a student model with mtd.convert(..., mode=[("kd_loss", {...})]) as in the configuration above.

  2. Train using Trainer with:

TrainingArguments(
    per_device_train_batch_size=1,
    gradient_accumulation_steps=8,
    ...
)
  1. Activation checkpointing is not enabled in this configuration.

  2. Observe the warnings being emitted repeatedly during the micro-batch forward passes.

Expected behavior

Could you please clarify whether these warnings are expected when using gradient accumulation without activation checkpointing?

If this is expected behavior, it would be helpful if the documentation could explain why the intermediate output is stored and confirm whether it is safely overwritten for each micro-batch rather than being incorrectly reused.

Alternatively, if these warnings indicate an issue with the current configuration, I would appreciate any guidance on the recommended setup.

Who can help?

System information

  • Container used (if applicable): none / bare venv

  • OS: Ubuntu Linux

  • CPU architecture: x86_64

  • GPU name: NVIDIA DGX B200

  • GPU memory size: 192GB

  • Number of GPUs: 1

  • Library versions:

    • Python: 3.12.3
    • ModelOpt version or commit hash: 0.46.1
    • CUDA: 13.2.86
    • PyTorch: 2.12.0.dev20260408+cu128
    • Transformers: 5.14.1
    • TensorRT-LLM: N/A
    • ONNXRuntime: N/A
    • TensorRT: N/A
  • Any other details: gradient_accumulation_steps=8, per_device_train_batch_size=1, activation checkpointing disabled.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions