Skip to content

Improve GenAI session: smarter max_length, DML skip, flat-decoder support, and response logging#1054

Merged
xieofxie merged 5 commits into
mainfrom
hualxie/genai_intel
Jul 6, 2026
Merged

Improve GenAI session: smarter max_length, DML skip, flat-decoder support, and response logging#1054
xieofxie merged 5 commits into
mainfrom
hualxie/genai_intel

Conversation

@xieofxie

@xieofxie xieofxie commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Several improvements to GenAI session benchmarking and hardware EP detection.

Smarter max_length allocation

_new_generator now computes max_length as prompt_len + max_new_tokens, capped at the bundle's context_length. This avoids pre-allocating the full KV cache (which can be 128K+ for DML bundles) when only a small generation is requested.

Hardware EP detection improvements

  • _bundle_uses_hardware_ep now returns the EP name (str | None) instead of bool, enabling better logging.
  • DML is now treated like CPU — bundles using only DML no longer trigger WinML EP registration, since DML doesn't need it.
  • Added support for flat-decoder layout (no pipeline wrapper), used by e.g. OpenVINO exports.

Response text capture and logging

  • Added response_text field to GenerationTiming to capture decoded model output.
  • The first iteration's response is logged at INFO level; subsequent iterations at DEBUG.
  • generate_timed now logs a summary line with input/output token counts and timing metrics.

Tests

  • Updated all _bundle_uses_hardware_ep tests to match the new return type.
  • Added tests for flat-decoder layout (OpenVINO, CPU-only, no provider options).
  • Added test_max_length_is_prompt_plus_max_new_tokens for the new max_length logic.
  • Added DML-only test case (test_dml_only_returns_none).

@xieofxie xieofxie requested a review from a team as a code owner July 6, 2026 02:54
@xieofxie

xieofxie commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

tested on

  • openvino npu
  • openvino gpu
  • dml
  • qnn

Comment thread src/winml/modelkit/session/genai_session.py Outdated
Move token collection from inside the per-token timing loop to after
generation completes, using generator.get_sequence(0) to fetch all
output tokens at once. This prevents get_next_tokens() from polluting
decode_s/TPOT measurements with host/device synchronization overhead
on hardware EPs.

@DingmaomaoBJTU DingmaomaoBJTU left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest commit (34eab68) resolves my earlier concern: token fetching via get_sequence() is now done after the timing loop, so decode_s/TPOT measurements are no longer polluted by potential host/device sync costs from get_next_tokens(). CI is green. LGTM.

@xieofxie xieofxie merged commit fe9ddc2 into main Jul 6, 2026
9 checks passed
@xieofxie xieofxie deleted the hualxie/genai_intel branch July 6, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants