Repository navigation
fix(inference): only retry batch-size probing on genuine OOM errors - #1608
Open
rtmalikian wants to merge 1 commit into
Open
rtmalikian wants to merge 1 commit into
rtmalikian wants to merge 1 commit into
Conversation
This branch has not been deployed
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
Fixes #1607: batch-size probing loops in the inference paths caught every
RuntimeErrorand retried withbatch_size * 3 // 4with no lower bound or termination. A non-OOM failure was silently swallowed, batch size 1 became 0 on the first retry, and a persistent error looped at zero forever. (Every probe site also carried a dead duplicateexcept torch.cuda.OutOfMemoryErrorbranch, unreachable because it subclassesRuntimeError.)Changes
FlagEmbedding/inference/utils.py(dependency-free) with three helpers:is_oom_error(e)— true for genuine OOM failures (CUDA / CPU allocator messages), coveringtorch.cuda.OutOfMemoryErrorshrink_batch_size_on_oom(batch_size, e)— returnsbatch_size * 3 // 4, re-raising the original OOM error when the result would drop below 1validate_batch_size(batch_size)— rejects non-positive caller-supplied batch sizes early withValueError(Nonestill allowed for the default fallback)RuntimeErrors now propagate immediately with their original traceback; only genuine OOM shrinks and retries;validate_batch_sizeat the top of each probing function. Files:encoder_only/base.py,encoder_only/m3.py,decoder_only/base.py,decoder_only/icl.py(2 sites),decoder_only/pseudo_moe.py,reranker/encoder_only/base.py,reranker/decoder_only/{base,layerwise,lightweight}.pytests/test_inference_batch_probing.py(13 tests, torch-free) covering helper behavior, fixed-loop semantics, and a structural sweep asserting every probe loop in the inference tree uses the fixed policyVerification
RuntimeErrorat batch size 1 → probe sizes[1, 0, 0, 0, 0, 0, 0, 0](swallowed, retried forever at 0)[1]; persistent OOM attempts[2, 1]then re-raises the original OOM (never 0); transient OOM at 32 recovers at 6 ([32, 24, 18, 13, 9, 6]);batch_size=0→ValueErrorpython3 -m unittest tests.test_inference_batch_probing: 13/13 OK; 3 structural tests verified to FAIL on the pre-fix tree (viagit stash) and pass afterpython3 -m py_compileclean on all changed filesAuthor
This PR was prepared with AI assistance and reviewed before submission.