Skip to content

Sort ALL_PRESET_NAMES so the preset list is deterministic - #503

Merged
stikves merged 2 commits into
apple:mainfrom
PratikDhanave:fix/deterministic-preset-order
Nov 11, 2026
Merged

stikves merged 2 commits into
apple:mainfrom
PratikDhanave:fix/deterministic-preset-order

Conversation

@PratikDhanave

@PratikDhanave PratikDhanave commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

ALL_PRESET_NAMES (python/src/coreai_models/export/presets.py) is built straight from a set union, so list_presets() and the Unknown compression preset '...'. Available: ... error name the presets in a different order every process (set iteration follows the per-process hash seed). Three consecutive runs on main:

['4bit_weights_8bit_kv_cache', 'none', '4bit_weight_palettized_group8', ...]
['4bit_weight_palettized_group8', 'none', '4bit_weight_palettized_group32', ...]
['4bit_weight_palettized_group8', '4bit_weight_palettized_group32', '4bit', ...]

The diffusion module's list_presets already returns sorted(PRESETS.keys()), and this module's own --list-presets CLI handler sorts too — the set ordering here is the odd one out, not a deliberate choice.

Change

ALL_PRESET_NAMES: list[str] = sorted(set(MACOS_PRESETS).union(IOS_PRESETS)), plus a regression test in test_from_preset.py asserting list_presets() equals the sorted union and ALL_PRESET_NAMES.

Verification

  • uv run pytest python/tests/test_model_units/test_export/test_from_preset.py -q → 52 passed.
  • Three post-fix runs produce identical sorted output (vs. three different orders on main).
  • CI's lint commands (uv run --frozen --only-group lint ruff check / ruff format --check, ruff 0.15.12) → clean.

Independent follow-up to #495 from the same audit.

Developed with AI assistance; reviewed and verified by the author.

@PratikDhanave
PratikDhanave requested a review from a team as a code owner November 8, 2026 07:16
@PratikDhanave
PratikDhanave force-pushed the fix/deterministic-preset-order branch from addfc60 to 9568319 Compare November 9, 2026 06:44
ALL_PRESET_NAMES was built straight from a set union, so list_presets()
and the "Unknown compression preset ... Available:" error named the
presets in a different order every process (set order follows the hash
seed). The diffusion module's list_presets already returns
sorted(PRESETS.keys()), and this module's own --list-presets CLI
handler sorts too; the set ordering here was the odd one out.

Sort the union and pin it with a test; across three runs the unsorted
list came out in three different orders, and sorted output is stable.
@PratikDhanave
PratikDhanave force-pushed the fix/deterministic-preset-order branch from 9568319 to 022b2ec Compare November 9, 2026 08:32
@stikves
stikves merged commit 0bfb548 into apple:main Nov 11, 2026
5 checks passed
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