Skip to content

cleanup(metax): decouple MetaxSDevices.ScoreNode from the scheduler policy string - #2413

Merged
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
asadjan4611:feat/metax-decouple-scorenode-policy
Aug 10, 2026
Merged

cleanup(metax): decouple MetaxSDevices.ScoreNode from the scheduler policy string#2413
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
asadjan4611:feat/metax-decouple-scorenode-policy

Conversation

@asadjan4611

@asadjan4611 asadjan4611 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

MetaxSDevices.ScoreNode previously changed its result based on the scheduler
policy string and carried a TODO: score should not depend on policy. It also
hard-coded a ±10000 magic number in the device layer whose only purpose was to
flip the score's sign so the best node would win under both the Binpack and
Spread sort directions. This coupled a device backend to scheduler-policy
concerns that belong in the shared policy layer.

This PR decouples them:

  • ScoreNode now returns a policy-independent score following a
    "higher score is a better node" convention, and the TODO is removed.
  • A new optional marker interface device.PolicyNeutralScorer lets a backend
    declare that its ScoreNode result is policy-independent.
  • The shared policy layer (policy.OverrideScore) applies the weight (10000)
    and the Spread-policy sign inversion (-10000) in one place, only for
    backends that opt in via the marker. Policy handling now lives in a single
    location, so future policies no longer require backend-specific changes.

The final weighted scores are numerically identical to the previous behavior
under both policies, so node ranking is unchanged. Backends that genuinely need
the policy string (e.g. Metax-GPU, which reads different annotations per
policy) do not implement the marker and are completely unaffected.

Which issue(s) this PR fixes:
Fixes #2404

Special notes for your reviewer:

  • No behavior change / ranking preserved. Binpack weight stays +10000 and
    Spread stays -10000, applied in OverrideScore instead of inside
    ScoreNode. For a raw device score s, the node's contribution is identical
    to before: +10000·s (binpack) and -10000·s (spread).
  • Opt-in, minimal blast radius. Only MetaxSDevices implements
    PolicyNeutralScorer. The other 12 device backends and the sibling
    Metax-GPU backend are untouched (verified by grep + build).
  • Tests added:
    • TestScoreNodePolicyIndependence — asserts ScoreNode returns the same
      value for binpack, spread, and "" across the online, topology-aware,
      and no-hint paths.
    • TestMetaxSDevicesImplementsPolicyNeutralScorer — asserts the marker is wired.
    • Two new TestOverrideScore cases — binpack (+600000) and spread
      (-600000) for the same input, proving ranking preservation.
  • Local checks: go build ./..., go vet, race-tested modified packages,
    gofmt/goimports, license headers, and golangci-lint v2.12.2 (0 issues)
    all pass.

Does this PR introduce a user-facing change?:

NONE

Summary by CodeRabbit

  • Bug Fixes

    • Improved device-aware node scoring for MetaX-SGPU workloads.
    • Ensured topology and online status are evaluated consistently across scheduler policies.
    • Preserved expected placement behavior for both Binpack and Spread scheduling through policy-aware score weighting.
  • Tests

    • Added coverage validating consistent scores across policies.
    • Added tests confirming correct score weighting for Binpack and Spread scheduling.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 38751535-e91b-4e1f-8a34-a0edcdfccfe8

📥 Commits

Reviewing files that changed from the base of the PR and between 24bddce and ab456b2.

📒 Files selected for processing (1)
  • pkg/scheduler/policy/node_policy.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/scheduler/policy/node_policy.go

📝 Walkthrough

Walkthrough

MetaxSDevices.ScoreNode now returns policy-independent scores. OverrideScore applies scheduler-policy weighting for policy-neutral backends. Tests cover score invariance, interface conformance, and Binpack or Spread results.

Changes

MetaX policy-neutral scoring

Layer / File(s) Summary
Define and implement policy-neutral scoring
pkg/device/metax/sdevice.go, pkg/device/metax/sdevice_test.go
ScoreNode no longer uses the scheduler policy string. MetaxSDevices implements PolicyNeutralScore. Tests verify policy-invariant scores and interface conformance.
Apply policy weighting in the scheduler
pkg/scheduler/policy/node_policy.go, pkg/scheduler/policy/node_policy_test.go
OverrideScore applies 10000 for Binpack and -10000 for Spread to policy-neutral scores. Tests verify the resulting scores.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • Project-HAMi/HAMi issue 2404: Removes scheduler-policy coupling from MetaxSDevices.ScoreNode and moves weighting to the shared policy layer.
  • Project-HAMi/HAMi issue 2439: Covers the same policy-neutral scoring pattern for a related MetaX backend.

Possibly related PRs

Suggested reviewers: archlitchi

Poem

A rabbit hops through scores so neat,
MetaX keeps policy off its feet.
Binpack weighs, Spread turns around,
Tests guard each topology-bound.
The rabbit cheers with carrots near.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes decoupling MetaxSDevices.ScoreNode from scheduler policy handling.
Linked Issues check ✅ Passed The changes satisfy the refactoring objectives in [#2404], including policy-independent scoring and shared policy weighting.
Out of Scope Changes check ✅ Passed The implementation and tests remain within the linked issue scope and support the requested scoring refactor.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/scheduler/policy/node_policy_test.go`:
- Around line 324-326: Replace the topology-aware annotation key at
pkg/scheduler/policy/node_policy_test.go:324-326 and
pkg/scheduler/policy/node_policy_test.go:374-376 with the required hami.io/
prefix, and migrate MetaxSGPUTopologyAware plus every producer and consumer in
the same change to use that hami.io/ annotation contract.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6849ddaf-e8c9-4f0b-82bd-219280fe3b3c

📥 Commits

Reviewing files that changed from the base of the PR and between 87d9795 and 6cb9323.

📒 Files selected for processing (5)
  • pkg/device/devices.go
  • pkg/device/metax/sdevice.go
  • pkg/device/metax/sdevice_test.go
  • pkg/scheduler/policy/node_policy.go
  • pkg/scheduler/policy/node_policy_test.go

Comment thread pkg/scheduler/policy/node_policy_test.go
@github-actions github-actions Bot added kind/bug Something isn't working and removed kind/cleanup labels Aug 6, 2026
@asadjan4611
asadjan4611 force-pushed the feat/metax-decouple-scorenode-policy branch from 6cb9323 to 84ccc66 Compare August 7, 2026 03:29
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@archlitchi

Copy link
Copy Markdown
Member

The title of this PR seems unrelated to the content

@asadjan4611 asadjan4611 changed the title fix(scheduler): enforce ResourceQuota for every device backend, refac… cleanup(metax): decouple MetaxSDevices.ScoreNode from the scheduler policy string Aug 8, 2026
@github-actions github-actions Bot removed the kind/bug Something isn't working label Aug 8, 2026
@asadjan4611

Copy link
Copy Markdown
Contributor Author

@archlitchi thanks for noticing i have update the title can you please check it

@Shouren Shouren left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@asadjan4611 Please rebase the master to fix the CI Workflow action.

Comment thread pkg/device/devices.go Outdated
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/device/metax/sdevice.go 66.66% 1 Missing ⚠️
Flag Coverage Δ
unittests 62.32% <90.00%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/scheduler/policy/node_policy.go 94.00% <100.00%> (+0.81%) ⬆️
pkg/device/metax/sdevice.go 80.24% <66.66%> (+3.43%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@asadjan4611

Copy link
Copy Markdown
Contributor Author

@Shouren can you please review it now

Comment thread pkg/scheduler/policy/node_policy.go Outdated
…string

MetaxSDevices.ScoreNode previously changed its result based on the
scheduler policy string and hard-coded a ±10000 weight in the device
layer. That weight existed only to flip the score's sign so the best
node would win under both the Binpack and Spread sort directions, and a
TODO noted that scoring should not depend on the policy.

ScoreNode now returns a policy-independent, "higher is a better node"
score. A new optional device.PolicyNeutralScorer marker interface lets a
backend declare this, and the shared scheduler policy layer
(OverrideScore) applies the weight and the Spread-policy sign inversion
in one place, only for backends that opt in. Only MetaxSDevices
implements the marker, so Metax-GPU and the other backends are
unaffected.

Node ranking is unchanged under both Binpack and Spread.

Fixes Project-HAMi#2404

Signed-off-by: asadjan4611 <asadjan4611@gmail.com>
…consumer

The PolicyNeutralScorer interface was exported from pkg/device even though
it has a single consumer (OverrideScore) and a single implementer. Move it
into pkg/scheduler/policy as an unexported policyNeutralScorer interface,
next to the code that uses it.

Because Go satisfies interfaces structurally, MetaxSDevices keeps its
exported PolicyNeutralScore() marker method and still satisfies the private
interface, so the capability is unchanged. The device package no longer
advertises a public abstraction with only one internal user.

Signed-off-by: asadjan4611 <asadjan4611@gmail.com>
@asadjan4611
asadjan4611 force-pushed the feat/metax-decouple-scorenode-policy branch from 24bddce to ab456b2 Compare August 10, 2026 13:00
@asadjan4611

Copy link
Copy Markdown
Contributor Author

@mesutoezdil can you please review it now.

@mesutoezdil

Copy link
Copy Markdown
Contributor

/lgtm

@asadjan4611

asadjan4611 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@mesutoezdil sorry for disturbance
can you please help me about this PR #2445
can i now work on it
cc @FouoF

@Shouren Shouren left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@hami-robot

hami-robot Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: asadjan4611, Shouren

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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.

MetaxSDevices.ScoreNode couples device scoring to the scheduler policy string

4 participants