docling
docling copied to clipboard
fix(vlm): expose generated token counts from the MLX engine
Problem
The MLX VLM runtime returns generation_time and model metadata, but it does not return num_tokens. The companion Transformers, vLLM, and API runtimes do return this field, and the VLM conversion stage consumes it when building predictions.
The MLX streaming loop already receives each generated token, so the count is available without changing generation behavior.
Proposed scope
- Count tokens emitted by
MlxVlmEngine.predict_batch()while it streams a response. - Store the count in
VlmEngineOutput.metadata["num_tokens"]. - Add a focused mocked unit regression that runs without an MLX model or Apple Silicon.
This is the remaining MLX-specific metadata gap noted in #3869; it does not revisit the API-engine implementation merged in #3818.