Skip to content

Added MDP generation to QEff Compile - #1086

Merged
quic-rishinr merged 8 commits into
quic:mainfrom
quic-mohmeh:mdp
Jun 26, 2026
Merged

Added MDP generation to QEff Compile#1086
quic-rishinr merged 8 commits into
quic:mainfrom
quic-mohmeh:mdp

Conversation

@quic-mohmeh

Copy link
Copy Markdown
Contributor

This PR adds MDP generation required for disaggregated serving for Prefill. Supports both Pipeline Prefill + Tensor Slicing and passing custom cores to the MDP generator. Also adds support for VLMs, compiler 'stages' option, and layerwise export.

Comment thread QEfficient/base/modeling_qeff.py Outdated

@ochougul ochougul left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please document what is tested with this here

@ochougul

Copy link
Copy Markdown
Contributor

Also can you check, if this info is getting included in hash/ dumped qconfigs for compile?

@quic-mohmeh

Copy link
Copy Markdown
Contributor Author

Also can you check, if this info is getting included in hash/ dumped qconfigs for compile?

Both mdp_num_partitions and mdp_strategy are included in hash, however mdp_strategy doesn't affect QPC at all. Let me know if you want to remove it

@quic-mohmeh

Copy link
Copy Markdown
Contributor Author

The unit tests are failing due to unable to connect to HF. It is not related to changes done in PR:
Short test summary:

2026-06-17T10:29:02.1205925Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[codegen] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1206154Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1206509Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_layerwise_supported_guard_rejects_unrelated_model - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1206731Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1207118Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[falcon] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1207336Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1207681Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_layerwise_matches_default_path_for_qwen3_5_moe - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1207898Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1208250Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[gpt2] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1208468Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1208824Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[gpt_oss] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1209042Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1209422Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[gptj] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1209637Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1209995Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[granite] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1210237Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1210617Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[llama] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1210836Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1211191Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[mistral] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1211410Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1211744Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_export_with_kv_cache_prefix - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1211962Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1212394Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[mixtral] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1212649Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1212985Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_export_default_names_unchanged - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.1213204Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.1213552Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[mpt] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3079746Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3080526Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[olmo2] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3081184Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3081794Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_export_prefix_changes_hash_dir - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3082781Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3083402Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[phi] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3084074Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3084750Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[phi3] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3085368Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3085989Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[qwen2] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3086611Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3087241Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_lm_cpu_runtime_parity_with_api_runner[starcoder2] - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3087868Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3088480Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_vlm_text_side_runtime_parity_and_full_export - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3089097Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3089808Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_text_embedding_cpu_parity_and_export - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3090402Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3091010Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_text_embedding_fp16_clip_transform_and_export - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3091624Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3092231Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_audio_embedding_ctc_cpu_parity_and_export - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3092906Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3093514Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_seq_classification_cpu_parity_and_export - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3094169Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3094745Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_whisper_export_smoke - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3095316Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3095946Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_causal_subfunction_export_smoke - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
2026-06-17T10:29:02.3096577Z Check your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
2026-06-17T10:29:02.3097205Z FAILED tests/unit_test/models/test_model_quickcheck.py::test_prefix_caching_continuous_batching_export_and_ort_smoke - OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.

@quic-mohmeh

quic-mohmeh commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Working for(with mdp_strategy='intersection')

  1. GPTOSS-20b with subfunc
  2. Llama3-8b with subfunc
  3. Qwen3VL-30B-A3B with subfunc and no layerwise
  4. Qwen/Qwen3.5-35B-A3B with subfunc with no layerwise
  5. gemma-4-26B-A4B with subfunc
  6. Qwen/Qwen3.6-35B-A3B with subfunc and no layerwise
  7. Qwen/Qwen3-235B-A22B with subfunc and no layerwise(PP2, PP8 and PP16)

with mdp_strategy='onnx'

  1. Qwen/Qwen3.5-35B-A3B with subfunc with no layerwise

@quic-akuruvil quic-akuruvil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@quic-mohmeh Have you verified thischanges with layerwise export also?

@quic-akuruvil quic-akuruvil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add unit-tests for this change, as mentioned in PR #930

@quic-mohmeh
quic-mohmeh force-pushed the mdp branch 2 times, most recently from 2b1f322 to d28db2f Compare June 19, 2026 09:51

@quic-hemagnih quic-hemagnih left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you please do the following, post to that I will merge it.

  1. Add unit test cases.
  2. Can you also add the results for all the models which you have verified with your PR.

@quic-mohmeh

quic-mohmeh commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Can you please do the following, post to that I will merge it.

  1. Add unit test cases.

Done, add the unit test for both Causal LM and MoE VLMs

  1. Can you also add the results for all the models which you have verified with your PR.

#1086 (comment)

@quic-mohmeh

Copy link
Copy Markdown
Contributor Author

@quic-mohmeh Have you verified thischanges with layerwise export also?

Not yet, haven't got the time

@quic-mohmeh

Copy link
Copy Markdown
Contributor Author

Please add unit-tests for this change, as mentioned in PR #930

Unit Tests Added

Two suites of CPU-only unit tests are added in tests/unit_test/base/test_modeling_qeff_base.py,
plus two new on-device compile-only integration tests in the existing causal LM and VLM test files.
No QAIC hardware is required to run the unit tests.


1. TestMdpLayerPartitionBounds — balanced remainder distribution (@pytest.mark.mdp @pytest.mark.cpu_only)

Tests the _layer_partition_bounds helper that decides how transformer layers are split across
pipeline partitions. The key invariant being validated is that remainder layers (when
num_layers % num_partitions != 0) are spread across middle partitions, keeping the last
partition lean and the load balanced.

Test What it checks
test_8_layers_3_partitions_counts 8 layers / 3 partitions produces counts [3, 3, 2]
test_10_layers_4_partitions_counts 10 layers / 4 partitions produces counts [2, 3, 3, 2]
test_max_minus_min_le_1_for_8_3 Max − min partition size ≤ 1 (balanced invariant) for 8/3
test_max_minus_min_le_1_for_10_4 Max − min partition size ≤ 1 (balanced invariant) for 10/4
test_last_partition_receives_base_allocation_8_3 Last partition always gets only floor(N/P) layers — never a remainder — for 8/3
test_last_partition_receives_base_allocation_10_4 Same invariant for 10/4
test_remainder_goes_to_middle_partitions_for_10_4 For 10/4, both remainder layers land on middle partitions (indices 1 and 2); partition 0 stays at base
test_evenly_divisible_has_zero_spread_12_4 When evenly divisible, all four partitions get exactly 3 layers each
test_two_partition_remainder_goes_to_first_5_2 Edge case: 5/2 with no middle zone — remainder goes to the first partition, giving [3, 2]
test_bounds_length_equals_num_partitions_minus_one The returned bounds list always has length num_partitions − 1 across all cases
test_total_layers_preserved Sum of per-partition counts always equals num_layers — no layers lost or duplicated

2. TestMdpCompileIntegration — end-to-end compile artifact validation (@pytest.mark.mdp @pytest.mark.cpu_only)

Uses a synthetic ONNX graph (no Hugging Face Hub download) whose nodes carry h.N/attn and
h.N/mlp names to exercise the full ONNX MDP strategy code path.
subprocess.run is monkeypatched so no real qaic-compile binary is needed.
The fixture builds a 2-layer GPT-2-shaped graph in a tmp_path, runs QEFFAutoModelForCausalLM._compile
with mdp_ts_num_devices=4, mdp_num_partitions=2, mdp_strategy="onnx", and then asserts on the
produced artifacts.

Test What it checks
test_mdp_disagg_json_is_created mdp_disagg_4d_2p.json is written to the compile directory
test_mdp_disagg_json_has_two_partitions The JSON contains exactly 2 partition entries
test_mdp_disagg_partition0_devices_are_0_1 Partition 0 is assigned device IDs [0, 1]
test_mdp_disagg_partition1_devices_are_2_3 Partition 1 is assigned device IDs [2, 3]
test_hashed_compile_params_command_references_mdp_json The compile command recorded in hashed_compile_params.json contains -mdp-load-partition-config= pointing at the disagg JSON
test_hashed_compile_params_contains_mdp_num_partitions hashed_compile_params.json records mdp_num_partitions=2 for cache-key stability
test_hashed_compile_params_contains_mdp_strategy_onnx hashed_compile_params.json records mdp_strategy="onnx"
test_hashed_compile_params_contains_mdp_ts_json The full generated MDP partition dict is embedded in hashed_compile_params.json under mdp_ts_json
test_qconfig_compiler_config_contains_mdp_num_partitions qconfig.json compiler_config section contains mdp_num_partitions=2
test_qconfig_compiler_config_contains_mdp_strategy_onnx qconfig.json compiler_config section contains mdp_strategy="onnx"

3. On-device compile-only integration tests (require @pytest.mark.on_qaic)

Two new parametrized tests exercise the full export → compile pipeline on real hardware in
compile-only mode (no inference run), keeping CI time low.

test_few_causal_lm_onnx_mdp_compile_only (tests/transformers/models/causal_lm_models/test_causal_lm_models.py)

  • Parametrized over all causal LM models in the test config × use_onnx_subfunctions=[False, True].
  • Calls check_causal_lm_pytorch_vs_kv_vs_ort_vs_ai100 with compile_only=True,
    mdp_num_partitions=2, mdp_strategy="onnx" to verify the compiler accepts the MDP partition
    config for every supported causal LM.

test_few_image_text_to_text_onnx_mdp_compile_only (tests/transformers/models/image_text_to_text/test_image_text_to_text_models.py)

  • Scoped to MoE VLMs only (test_mm_moe_models — models where model_type contains "moe").
  • Parametrized over kv_offload=[True, False]; dual-QPC models are skipped unless kv_offload=True.
  • Runs with use_onnx_subfunctions=True, mdp_num_partitions=2, mdp_strategy="onnx",
    compile_only=True. For non-InternVL / non-Molmo models, skip_vision=True is also set so only
    the text backbone is compiled with MDP.

@quic-mohmeh

Copy link
Copy Markdown
Contributor Author

@quic-hemagnih The PR is good to merge

Comment thread QEfficient/compile/mdp_generator.py
Comment thread tests/unit_test/base/test_modeling_qeff_base.py
Comment thread QEfficient/base/modeling_qeff.py

@quic-amitraj quic-amitraj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The PR adds a significant new API surface (mdp_num_partitions, mdp_strategy, mdp_compiler_dump_path) but ships no example showing how to use it. please consider adding one example script to demonstrate its use.

Comment thread QEfficient/compile/mdp_generator.py Outdated
Comment thread QEfficient/compile/mdp_generator.py Outdated
Comment thread QEfficient/base/modeling_qeff.py
@quic-mohmeh

quic-mohmeh commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the latest feedback and pushed updates. Added the Qwen3-VL compile-only MDP example script, documented it in the examples READMEs, fixed Ruff formatting, and CI checks are green.

@quic-amitraj @quic-hemagnih PR is good to merge

Comment thread QEfficient/base/modeling_qeff.py Outdated
@quic-amitraj

Copy link
Copy Markdown
Contributor

Others LGTM @quic-rishinr

@quic-mohmeh

quic-mohmeh commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the latest review feedback and pushed 39af48f.

@quic-rishinr

Copy link
Copy Markdown
Contributor

This PR doesnt handle Qwen 3.5 122B and 397B. A separate PR will be raised for it.

@ochougul

Copy link
Copy Markdown
Contributor

the mdp_ts_num_devices is sent as 4 in case of TS4PP6 case, but this value is never used in the code, as it's overridden by num_devices while calling self._compile causing same argument passed twice, once via passed argument and once via kwargs.

Just tried to run the example script errors out with following

  File "/home/ochougul/layerwise_new/examples/disagg_serving/qwen3_vl_mdp_compile.py", line 146, in main
    prefill_qpc_path = qeff_model.compile(
                       ^^^^^^^^^^^^^^^^^^^
  File "/home/ochougul/layerwise_new/QEfficient/transformers/models/modeling_auto.py", line 2089, in compile
    lang_qpc_path = self.lang_model._compile(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: QEfficient.utils._utils.dump_qconfig.<locals>.wrapper() got multiple values for keyword argument 'mdp_ts_num_devices'

Add QEfficient/compile/mdp_generator.py implementing two strategies for
generating MDP partition configs for pipeline-parallel (PP) disaggregated
prefill serving:

  MdpStrategy.ONNX (default)
    Single-pass ONNX topsort walk; assigns each node to a partition by
    transformer layer index (layers.N / h.N / layer_N// naming patterns).
    Non-layer nodes (embeddings, lm_head) follow the nearest layer.
    Inlined local function call-sites (CtxScatterCB / CtxGatherCB) are
    expanded inline so nodeList order matches the ONNX topsort.  Known
    custom ops (CustomRMSNorm, CastToUInt4) are included by call-site name.
    Produces a ~19 MB JSON superset of the compiler IR.

  MdpStrategy.INTERSECTION
    Runs the ONNX strategy first (superset), then filters each partition's
    nodeList to only names present in a prior qaic-compile
    -mdp-dump-partition-config dump.  Result is compact (~1-2 MB) and
    contains only exact-match Glow IR names for doManualPartitioning().
    Requires a prior compile run to produce the dump path.

Integrate into QEfficient/base/modeling_qeff.py:
  - New compile() parameter mdp_num_partitions (default 1, existing
    template/TS behaviour unchanged).
  - When mdp_num_partitions > 1, auto-generate the MDP JSON from the
    exported ONNX and pass it to qaic-compile via mdp_load_partition_config.
  - Strategy and optional compiler dump path controllable via
    mdp_strategy / mdp_compiler_dump_path in compiler_options.
  - MdpStrategy enum exported for type-safe caller use.
  - Compile hash includes mdp_num_partitions to avoid stale QPC reuse.

Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Previously, generate_disagg_mdp_partition_config distributed remainder
layers (num_layers % num_partitions) entirely into the last partition
via a min(..., num_partitions - 1) clamp.  This left the last stage
holding postprocessing (lm_head, final norm) plus all the overflow,
creating a consistent pipeline bottleneck.

Replace the flat floor-division heuristic with a balanced breakpoint
scheme implemented in the new _compute_partition_breakpoints helper:

  - Last partition always receives the base allocation (base = num_layers
    // num_partitions), keeping postprocessing light.
  - Remainder layers fill the middle stages first (indices 1 ..
    num_partitions-2), distributed centre-outward within the middle zone
    so the load stays as symmetric as possible.
  - The first partition (embedding preprocessing) absorbs overflow only
    when the remainder exceeds the number of available middle stages.
  - Worst case (remainder == num_partitions - 1): every stage except the
    last receives one extra layer.

Example:  8 layers / 3 stages
  before: [2, 2, 4]
  after:  [3, 3, 2]

Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
@quic-rishinr

Copy link
Copy Markdown
Contributor

There are two pending issues with the MDP changes in this PR:

  1. With the current changes, compilation is failing for Qwen 3.5 122B and Qwen 3.5 397B. This needs to be fixed separately as a follow-up bug.

  2. In the TS4PP6 case, mdp_ts_num_devices is set to 4, but this value is never actually used. It gets overridden by num_devices during the self._compile call, resulting in the same argument being passed twice (once explicitly and once via kwargs). This should be addressed in a separate bug fix.
    @quic-mohmeh please raise a follow-up PR to address these issues. Merging this PR to unblock PP support.
    @anujgupt-github FYI

@quic-rishinr
quic-rishinr merged commit 1a001e2 into quic:main Jun 26, 2026
6 checks passed
ochougul pushed a commit that referenced this pull request Jun 26, 2026
This PR adds MDP generation required for disaggregated serving for
Prefill. Supports both Pipeline Prefill + Tensor Slicing and passing
custom cores to the MDP generator. Also adds support for VLMs, compiler
'stages' option, and layerwise export.

---------

Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Signed-off-by: ochougul <ochougul@qti.qualcomm.com>
quic-rishinr pushed a commit that referenced this pull request Jun 26, 2026
This PR adds MDP generation required for disaggregated serving for
Prefill. Supports both Pipeline Prefill + Tensor Slicing and passing
custom cores to the MDP generator. Also adds support for VLMs, compiler
'stages' option, and layerwise export.

---------

Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Signed-off-by: ochougul <ochougul@qti.qualcomm.com>
(cherry picked from commit 5ca7a31)
Signed-off-by: Rishin Raj <rishinr@qti.qualcomm.com>
quic-rishinr added a commit that referenced this pull request Jun 29, 2026
This PR adds MDP generation required for disaggregated serving for
Prefill. Supports both Pipeline Prefill + Tensor Slicing and passing
custom cores to the MDP generator. Also adds support for VLMs, compiler
'stages' option, and layerwise export.

---------

Signed-off-by: Mohit Mehta <mohmeh@qti.qualcomm.com>
Signed-off-by: ochougul <ochougul@qti.qualcomm.com>
Signed-off-by: Rishin Raj <rishinr@qti.qualcomm.com>
Co-authored-by: quic-mohmeh <mohmeh@qti.qualcomm.com>
Co-authored-by: Rishin Raj <rishinr@qti.qualcomm.com>
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.

6 participants