Skip to content

Conversation

@yifant-code
Copy link

@yifant-code yifant-code commented Dec 10, 2025

Fixes #12836

Problem

Server crashes with GGML_ASSERT failure when running embeddings with -b > -ub:
Embeddings use non-causal attention which requires all tokens in a single ubatch. When n_batch > n_ubatch, the server attempts to split processing, triggering the assertion.

Solution

Add parameter validation in main() after common_params_parse():

  • Detect when --embedding is enabled and n_batch > n_ubatch
  • Log warnings explaining the auto-correction
  • Set n_batch = n_ubatch to prevent crash

Follows @ggerganov's suggested approach in #12836.

Testing

  • ✅ Built server with fix
  • ✅ Tested with problematic config: ./llama-server -m model.gguf --embedding -b 2048 -ub 512
  • ✅ Confirmed warning logs appear and parameters are auto-corrected
  • ✅ Verified server starts successfully (no GGML_ASSERT crash)
  • ✅ Tested valid configurations to ensure no false positives

Note

Supersedes stalled PR #12940 which attempted a runtime fix in the old examples/server/ location. This implementation validates at startup in tools/server/ (current location) per maintainer guidance.

Fixes ggml-org#12836 where the server crashes with GGML_ASSERT failure when
running with embeddings enabled and n_batch > n_ubatch.

Root cause: Embeddings use non-causal attention which requires all
tokens to be processed within a single ubatch. When n_batch > n_ubatch,
the server attempts to split processing, causing assertion failure.

Solution:
- Add parameter validation in main() after common_params_parse()
- When embeddings enabled and n_batch > n_ubatch:
  * Log warnings explaining the issue
  * Automatically set n_batch = n_ubatch
  * Prevent server crash

This follows the approach suggested by @ggerganov in issue ggml-org#12836.

Note: This supersedes stalled PR ggml-org#12940 which attempted a runtime fix
in the old examples/server/server.cpp location. This implementation
validates at startup in tools/server/server.cpp (current location).

Testing:
- Build: Compiles successfully
- Validation triggers: Warns when -b > -ub with --embedding
- Auto-correction works: Adjusts n_batch = n_ubatch
- No false positives: Valid params don't trigger warnings
- Verified on macOS M3 Pro with embedding model
@yifant-code yifant-code force-pushed the fix/embedding-batch-validation branch from aae2567 to 2722844 Compare December 10, 2025 23:34
@yifant-code yifant-code marked this pull request as ready for review December 10, 2025 23:38
@aviallon
Copy link
Contributor

This is quite relevant to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server : crash when -b > -ub with embeddings

2 participants