fix: defer heavy imports in inference CLI for vLLM compat#53
Open
slacki-ai wants to merge 2 commits intolongtermrisk:v0.9from
Open
fix: defer heavy imports in inference CLI for vLLM compat#53slacki-ai wants to merge 2 commits intolongtermrisk:v0.9from
slacki-ai wants to merge 2 commits intolongtermrisk:v0.9from
Conversation
Move torch, vLLM, transformers, and huggingface_hub imports from module top-level to the __main__ guard. This allows monkey-patches (tqdm rate limiting, tokenizer compat) to be applied BEFORE vLLM is imported, since vLLM captures tqdm and tokenizer behaviour at import time. Also changes main() signature to accept pre-parsed (cfg, conversations) instead of a raw JSON string, and adds tqdm noise reduction and transformers all_special_tokens_extended compat patch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Keep 5 deferred-import checks (one per heavy library). Remove 6 tests: stdlib presence check, function signature checks, __main__ guard existence, and AST-dump string matching for imports inside the guard. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
Why do we need this? I strongly prefer imports at module level. Modifying tqdm behavior is imo probably not worth such a change. Why does the tokenizer need any monkeypatching? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
torch,vllm,transformers,huggingface_hub, andopenweights.clientimports from module top-level into the__main__guardtqdmand tokenizer behaviour at import time, so patching after import has no effecttqdmnoise reduction (rate-limited updates) andtransformers.PreTrainedTokenizerBase.all_special_tokens_extendedcompat patch for newer transformers versionsmain()signature frommain(config_json: str)tomain(cfg, conversations)— config parsing and data loading now happen in__main__before vLLM importChanges
openweights/jobs/inference/cli.py— restructured import order andmain()signatureTest plan
main()signature correct,__main__guard contains deferred imports🤖 Generated with Claude Code