Skip to content

Sentence transformer prefetch: skip a trainer class without get_train_dataloader - #17893

Merged
danielhanchen merged 1 commit into
mainfrom
fix-st-prefetch-missing-loader
Nov 16, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-st-prefetch-missing-loader

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Repo tests (CPU, rest-2) has failed on main since #17859 (FastSentenceTransformer background collation):

tests/test_mixed_nvidia_capabilities.py::test_sentence_transformer_trainer_checks_the_placement_before_the_deferred_compile[trainer_init]
tests/test_mixed_nvidia_capabilities.py::test_sentence_transformer_trainer_checks_the_placement_before_the_deferred_compile[before_train]
unsloth/models/sentence_transformer.py:3448: in _patch_sentence_transformer_trainer
unsloth/models/_sentence_transformer_prefetch.py:116:
E   AttributeError: type object 'SentenceTransformerTrainer' has no attribute 'get_train_dataloader'

_patch_sentence_transformer_trainer now ends with patch_train_dataloader(SentenceTransformerTrainer), which reads trainer_class.get_train_dataloader unconditionally. The placement tests patch a minimal stand-in trainer (just __init__ and train), so the call raises after __init__ and train were already patched.

The real SentenceTransformerTrainer always has the method (it is a transformers Trainer), so #17859 is correct for the shipped classes. Still, the prefetch wrapper is an add-on: a trainer class with no train loader has nothing to prefetch and should not abort the rest of the patching.

Change

  • patch_train_dataloader returns early when the class has no get_train_dataloader. Classes that do have it are wrapped exactly as before.
  • New tests/test_st_training_fast_paths.py::test_prefetch_patch_skips_a_trainer_without_a_train_dataloader pins that. It fails without the change.

Verification

tests/test_st_training_fast_paths.py tests/test_mixed_nvidia_capabilities.py: 91 passed. On main, the two placement cases fail as above.

…_dataloader

#17859 made _patch_sentence_transformer_trainer end with patch_train_dataloader, which read
trainer_class.get_train_dataloader unconditionally. The placement tests in test_mixed_nvidia_capabilities.py
patch a minimal SentenceTransformerTrainer stand-in, so the patch raised AttributeError after installing
__init__ / train and the two cases failed on main. With no loader method there is nothing to prefetch;
return and keep the other patches.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 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-16T03:45:54.875283Z 64f754d 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 64f754db65

ℹ️ 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 7a5025b into main Nov 16, 2026
@danielhanchen
danielhanchen deleted the fix-st-prefetch-missing-loader branch November 16, 2026 03:57
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