Skip to content

[TableTransformer, PI0] Fix stale expected values and OOM in integration tests - #48198

Merged
ydshieh merged 10 commits into
mainfrom
fix_table_transformer_t5_pi0
Aug 21, 2026
Merged

ydshieh merged 10 commits into
mainfrom
fix_table_transformer_t5_pi0

Conversation

@ydshieh

@ydshieh ydshieh commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

CPU CI GPU run-slow

What

Fixes two slow integration test failures on A10G GPU (sm_86, torch 2.13):

TableTransformer — stale expected values (test_table_detection)

Expected logit and box values were captured on an older GPU/torch
combination. A10G (sm_86) produces slightly different fp32 results that
fall just outside the existing atol=1e-4 tolerance. Adds ("cuda", 8)
entries to the Expectations blocks with values captured on the runner.

PI0 — OOM during training (test_train_pi0_base_libero)

The test loaded lerobot/pi0_base (PaLiGemma-3B backbone) in float32
with the default Adam optimizer, which OOMs on a 22 GiB A10G GPU.
Adam's optimizer states (exp_avg + exp_avg_sq) cost ~12 GB on top of
the model weights (~12 GB in float32), totalling well over 22 GB.

Fix:

  • torch_dtype=torch.bfloat16 — halves model footprint to ~6 GB
  • optim="adafactor" — factored 2nd moment, no 1st moment; optimizer
    state drops from ~12 GB to ~0.3 GB
  • per_device_train_batch_size=2 — reduces activation memory
  • max_steps=6 — one extra step for a clearer loss trend
  • Relaxed loss assertion to allow 1 non-monotone step: with a small
    batch size and bf16 precision, occasional gradient noise can cause a
    single step to tick up even as the overall trend is downward
  • @require_torch_non_multi_accelerator — on multi-GPU runners, Trainer
    wraps the model in nn.DataParallel, which scatters float32 dataset
    inputs to replicas while model weights are bfloat16, causing a dtype
    mismatch. This test is not intended to cover multi-GPU training, so it
    is skipped on multi-GPU setups via the decorator.

Test plan

  • test_table_detection — verified on A10G runner (passes)
  • test_train_pi0_base_libero — verified on A10G runner (passes, ~33s)

ydshieh and others added 2 commits August 21, 2026 21:10
- TableTransformer: stale expected logit/box values for A10G (sm_86)
- T5: CUDAGraphs tensor overwrite in test_compile_static_cache, likely
  introduced by #47731 (stop setting static cache as model attribute)
- PI0: OOM in test_train_pi0_base_libero (float32 training on 22 GiB GPU)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add ("cuda", 8) entries to expected_logits_data and expected_boxes_data
in test_table_detection, captured on A10G (compute capability 8.6).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

The test loaded pi0_base (PaLiGemma-3B-based) in float32 and ran full
Trainer training, which OOMs on a 22 GiB A10G GPU. Switch to bfloat16
(torch_dtype=torch.bfloat16 + TrainingArguments(bf16=True)) to halve
the memory footprint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ydshieh ydshieh changed the title [WIP] Fix integration test failures: TableTransformer, T5 compile, PI0 [TableTransformer, PI0] Fix stale expected values and OOM in integration tests Aug 21, 2026
…None)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ydshieh

ydshieh commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

run-slow: pi0, table_transformer

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/pi0", "models/table_transformer"]
quantizations: []

@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 5f1555f5 workflow commit (merge commit)
PR 3bf5b117 branch commit (from PR)
main e453228e base commit (on main)

⚠️ No test being reported (jobs are skipped or cancelled)!

ydshieh and others added 2 commits August 21, 2026 22:28
The test loaded pi0_base (PaLiGemma-3B backbone) in float32 with default
Adam optimizer, which OOMs on a 22 GiB A10G GPU: Adam stores exp_avg +
exp_avg_sq (~12 GB) on top of the model weights (~6 GB) and gradients
(~6 GB), totalling ~24 GB regardless of batch size.

Fix:
- torch_dtype=torch.bfloat16 (halves model footprint)
- optim="adafactor" (factored 2nd moment, no 1st moment; ~0.3 GB vs 12 GB)
- per_device_train_batch_size=2 (reduces activation memory)
- max_steps=6 (one extra step for a clearer trend)
- Relax the loss assertion to allow 1 non-monotone step: with a small
  batch size and bf16 precision, occasional gradient noise can cause a
  single step to tick up even as the overall trend is downward.

Verified on A10G runner (22 GiB).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ydshieh

ydshieh commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

run-slow: pi0

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/pi0"]
quantizations: []

@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 4763d100 workflow commit (merge commit)
PR cd6eef0f branch commit (from PR)
main e453228e base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

On multi-GPU runners Trainer wraps the model in nn.DataParallel, which
scatters float32 dataset inputs to each GPU replica. The model weights
are bfloat16, causing a dtype mismatch in the first linear layer.

Setting device_map={"": torch_device} causes from_pretrained to record
model.hf_device_map, which Trainer checks to skip DataParallel wrapping.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: pi0, table_transformer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ydshieh

ydshieh commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

run-slow: pi0

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/pi0"]
quantizations: []

@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN e4dffd0d workflow commit (merge commit)
PR ac078917 branch commit (from PR)
main e453228e base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

ydshieh and others added 2 commits August 21, 2026 23:00
Replace device_map approach (which only skips DataParallel when the
model spans multiple GPUs) with explicitly setting trainer.args._n_gpu=1
before training. This reliably prevents Trainer from wrapping the model
in nn.DataParallel regardless of how many GPUs are available.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…unners

On multi-GPU machines Trainer wraps the model in nn.DataParallel, which
scatters float32 dataset inputs to replicas while the model weights are
bfloat16, causing a dtype mismatch. This test is not intended to cover
multi-GPU training, so skip it on multi-GPU setups via the decorator.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ydshieh

ydshieh commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

run-slow: pi0

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/pi0"]
quantizations: []

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 32526736515:1
Result: success | Jobs: 1 | Tests: 6 | Failures: 0 | Duration: 39s

@ydshieh
ydshieh merged commit d56c55b into main Aug 21, 2026
34 of 35 checks passed
@ydshieh
ydshieh deleted the fix_table_transformer_t5_pi0 branch August 21, 2026 21:11
@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN a81161e6 workflow commit (merge commit)
PR e654d9db branch commit (from PR)
main e453228e base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

sbucaille pushed a commit to sbucaille/transformers that referenced this pull request Sep 16, 2026
…ion tests (huggingface#48198)

* [WIP] Fix integration test failures: TableTransformer, T5 compile, PI0

- TableTransformer: stale expected logit/box values for A10G (sm_86)
- T5: CUDAGraphs tensor overwrite in test_compile_static_cache, likely
  introduced by huggingface#47731 (stop setting static cache as model attribute)
- PI0: OOM in test_train_pi0_base_libero (float32 training on 22 GiB GPU)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [TableTransformer] Fix stale expected values for A10G (sm_86)

Add ("cuda", 8) entries to expected_logits_data and expected_boxes_data
in test_table_detection, captured on A10G (compute capability 8.6).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [PI0] Fix OOM in test_train_pi0_base_libero by using bfloat16

The test loaded pi0_base (PaLiGemma-3B-based) in float32 and ran full
Trainer training, which OOMs on a 22 GiB A10G GPU. Switch to bfloat16
(torch_dtype=torch.bfloat16 + TrainingArguments(bf16=True)) to halve
the memory footprint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [TableTransformer] Use (None, None) fallback key instead of ("cuda", None)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [PI0] Fix OOM in test_train_pi0_base_libero (bfloat16 + adafactor)

The test loaded pi0_base (PaLiGemma-3B backbone) in float32 with default
Adam optimizer, which OOMs on a 22 GiB A10G GPU: Adam stores exp_avg +
exp_avg_sq (~12 GB) on top of the model weights (~6 GB) and gradients
(~6 GB), totalling ~24 GB regardless of batch size.

Fix:
- torch_dtype=torch.bfloat16 (halves model footprint)
- optim="adafactor" (factored 2nd moment, no 1st moment; ~0.3 GB vs 12 GB)
- per_device_train_batch_size=2 (reduces activation memory)
- max_steps=6 (one extra step for a clearer trend)
- Relax the loss assertion to allow 1 non-monotone step: with a small
  batch size and bf16 precision, occasional gradient noise can cause a
  single step to tick up even as the overall trend is downward.

Verified on A10G runner (22 GiB).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [PI0] Add comment explaining why adafactor is used

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [PI0] Fix dtype mismatch on multi-GPU machines (DataParallel + bfloat16)

On multi-GPU runners Trainer wraps the model in nn.DataParallel, which
scatters float32 dataset inputs to each GPU replica. The model weights
are bfloat16, causing a dtype mismatch in the first linear layer.

Setting device_map={"": torch_device} causes from_pretrained to record
model.hf_device_map, which Trainer checks to skip DataParallel wrapping.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [PI0] Extend device_map comment to clarify single-device intent

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [PI0] Fix DataParallel dtype mismatch on multi-GPU runners

Replace device_map approach (which only skips DataParallel when the
model spans multiple GPUs) with explicitly setting trainer.args._n_gpu=1
before training. This reliably prevents Trainer from wrapping the model
in nn.DataParallel regardless of how many GPUs are available.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [PI0] Use @require_torch_non_multi_accelerator to skip on multi-GPU runners

On multi-GPU machines Trainer wraps the model in nn.DataParallel, which
scatters float32 dataset inputs to replicas while the model weights are
bfloat16, causing a dtype mismatch. This test is not intended to cover
multi-GPU training, so skip it on multi-GPU setups via the decorator.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
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