- Notifications
You must be signed in to change notification settings - Fork14.2k
server: validate n_batch == n_ubatch for embeddings (#6263)#18123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
yifant-code wants to merge1 commit intoggml-org:masterChoose a base branch fromyifant-code:fix/embedding-ubatch-validation
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Draft
server: validate n_batch == n_ubatch for embeddings (#6263)#18123
yifant-code wants to merge1 commit intoggml-org:masterfromyifant-code:fix/embedding-ubatch-validation
+15 −9
Conversation
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
Fixesggml-org#6263 where server accepts mismatched batch/ubatch values withembeddings, leading to suboptimal or incorrect behavior.Problem: Embeddings and reranking use non-causal attention which requiresall tokens to be processed within a single ubatch. When n_batch != n_ubatch,the configuration is incoherent. Default values differ (n_batch=2048,n_ubatch=512), so users encounter this frequently.Solution:- Add parameter validation in main() after common_params_parse()- When embeddings enabled and n_batch != n_ubatch: * Log warnings explaining the requirement * Automatically set both to min(n_batch, n_ubatch) * Ensure coherent configurationThis follows the auto-correction approach suggested by@mirekphdand provides better UX than strict rejection.Testing:✅ Builds successfully✅ Validation triggers: -b 2048 -ub 512 --embedding → logs warnings, adjusts both to 512✅ No false positives: -b 512 -ub 512 --embedding → no warnings✅ Verified on macOS M3 Pro with embedding model
cc00104 to3827a23CompareSign up for freeto 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.
Fixes#6263
Problem
Server accepts mismatched
--batch-sizeand--ubatch-sizevalues when--embeddingis enabled, leading to incoherent configuration.Embeddings use non-causal attention which requires all tokens in a single ubatch (
n_batch == n_ubatch). Default values differ (n_batch=2048, n_ubatch=512), so users frequently encounter this issue.Solution
Add parameter validation in
main():--embeddingenabled andn_batch != n_ubatchmin(n_batch, n_ubatch)Uses auto-correction approach (suggested by@mirekphd) for better UX than strict rejection.
Testing
✅ Builds successfully
✅ Validation triggers:
-b 2048 -ub 512 --embedding→ logs warnings, sets both=512✅ No false positives:
-b 512 -ub 512 --embedding→ silent✅ Tested on macOS M3 Pro with embedding model