Skip to content

Studio DiT training: record a failed text-encoder streaming setup as type and message only - #18567

Merged
danielhanchen merged 1 commit into
mainfrom
fix-recheck-lasterror-traceback
Nov 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-recheck-lasterror-traceback

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

#18123 added text-encoder layer streaming for DiT training captioning. When the streaming setup fails, place_text_encoders undoes any half-streamed encoder and lets the caller move the encoders whole, but first it stores the exception object in the module global diffusion_te_stream.LAST_ERROR. The exception's traceback keeps the placement frame alive, and that frame references the training pipeline, the candidate encoders and, when the streamer constructor failed, its partially built state (the host arena). So after one failed setup, the pipeline and those host / GPU buffers stay referenced for the life of the worker, even once training releases its own references. Nothing reads the object itself: LAST_ERROR is only a diagnostic.

Change

LAST_ERROR now holds "Type: message" (a plain string) instead of the exception. The status a reader would need is still there. The traceback, its frames and anything they reference are dropped when the handler returns. Nothing else changes: the fallback, the undo of a half-streamed encoder and the return value stay the same.

Tests

test_a_failed_setup_records_the_error_without_keeping_the_pipeline_alive makes the streamer constructor allocate a buffer and then raise through the real place_text_encoders entry point. It checks that the error type and message are recorded, then drops the last caller reference to the pipeline, runs gc.collect(), and checks that the pipeline and encoder are freed. On main it fails because the pipeline is still alive through LAST_ERROR. With this change it passes. tests/test_diffusion_train_te_stream.py: main 13 passed, 2 skipped (CUDA) plus the new test failing. Head: 14 passed, 2 skipped.

Not proven here

The test is CPU-only and uses a fake streamer. The real CUDA arena release after a failed setup (memory returned to the allocator / unpinned) was not measured on a GPU. That would need a run that injects a failure into TextEncoderStreamer on a CUDA card and compares torch.cuda.memory_allocated() and the pinned host total before and after gc.collect().

…type and message only

LAST_ERROR held the exception object, whose traceback kept the placement frame alive: the
training pipeline, its candidate encoders and a partially built streamer were never freed
after a failed setup. Store "Type: message" instead.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: 🔄 Running

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-11-20T05:34:41.208273Z 3e1fe9e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T05:37:46.539517Z 3e1fe9e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 3e1fe9e375

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 44067a8 into main Nov 20, 2026
@danielhanchen
danielhanchen deleted the fix-recheck-lasterror-traceback branch November 20, 2026 07:14
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.

1 participant