Skip to content

fix(ascend): stop whole-card/memory-less hami-core requests from bypassing the node mode gate - #2029

Merged
hami-robot[bot] merged 3 commits into
Project-HAMi:masterfrom
Wangmin362:fix/ascend-hamicore-wholecard-mode-gate
Jul 9, 2026
Merged

fix(ascend): stop whole-card/memory-less hami-core requests from bypassing the node mode gate#2029
hami-robot[bot] merged 3 commits into
Project-HAMi:masterfrom
Wangmin362:fix/ascend-hamicore-wholecard-mode-gate

Conversation

@Wangmin362

@Wangmin362 Wangmin362 commented Jul 8, 2026

Copy link
Copy Markdown
Member

What this PR does

Fixes #2028.

The node soft/hard-split exclusivity added in #1812 rejects a mismatched pod with ModeNotFit, but the check sits inside request.Memreq > 0 && request.Memreq < totalMemPerCard && request.Nums > 0. A whole-card memory request (Memreq == card capacity) or a memory-less request (Memreq == 0) skips the block, so a hami-core (soft-split) pod can be scheduled onto a hard-split node.

This PR lifts the soft-pod arm out of the memory-range condition: a pod that declares vnpu-mode: hami-core must land on a hami-core node regardless of how much memory it requests.

// applies to whole-card and memory-less requests too
if isHAMiCore && !nodeSupportHamiCore {
    reason[common.ModeNotFit]++
    return false, nil, common.GenReason(reason, len(devices))
}

// reverse arm kept inside the memory-range condition on purpose
if request.Memreq > 0 && request.Memreq < totalMemPerCard && request.Nums > 0 {
    if nodeSupportHamiCore && !isHAMiCore {
        reason[common.ModeNotFit]++
        return false, nil, common.GenReason(reason, len(devices))
    }
}

Why only the soft-pod arm (not a symmetric change)

The reverse arm (a legacy/whole-card pod on a hami-core node) is deliberately left inside the memory-range condition. Making it symmetric would newly reject plain whole-card jobs on any hami-core node, and because nodeSupportHamiCore defaults to the global hamiVnpuCore value, a cluster with hamiVnpuCore: true would then reject every whole-card legacy request. A hami-core pod on a hard node is a correctness problem (no soft-split limiter to enforce its limits); a legacy whole-card pod on a hami-core node is not — so only the soft-pod direction is unconditional.

Testing

Unit tests

pkg/device/ascend TestDevices_Fit: 115/115 pass, go build/vet/gofmt clean. Added 4 cases:

  • whole-card (Memreq == capacity) hami-core on hard node → ModeNotFit
  • memory-less (Memreq == 0) hami-core on hard node → ModeNotFit
  • whole-card hami-core on hami-core node → fits (not over-blocked)
  • whole-card legacy on hami-core node → fits (regression guard for the asymmetry above)

Real hardware (8× Ascend 910B4, hard node) — before/after A/B

Same scheduler build, toggling only this change (v2.9.0 and master have this gate byte-identical):

case (all vnpu-mode: hami-core) before after
partial mem 16384 Pending ModeNotFit Pending ModeNotFit
partial mem 32767 Pending ModeNotFit Pending ModeNotFit
whole-card mem 32768 bound to hard node (bypass) Pending ModeNotFit
memory-less bound to hard node (bypass) Pending ModeNotFit
legacy whole-card (no vnpu-mode) Running Running (not over-blocked)

Before: FilteringSucceed: 1 nodes fit(node-001) + BindingSucceed for the whole-card hami-core pod.
After: NodeUnfitPod ... reason="1/8 ModeNotFit" for the same pod; the legacy whole-card pod still schedules.

Scope note

The bypass is confirmed on real hardware. Demonstrating the runtime failure of a whole-card soft pod on a hard-only node needs a second node without soft-split assets, which I can't construct on a single node (the device-plugin always ships soft-split assets). See the linked issue.


This PR was written with AI assistance (Claude Code): the analysis is from my own testing on real Ascend 910B4 hardware, and the code and tests were drafted with AI and reviewed/validated by me.

Summary by CodeRabbit

  • Bug Fixes
    • Improved core-mode (hami-core) scheduling by rejecting incompatible nodes earlier when the pod requests core-mode but the node doesn’t support it.
    • Tightened compatibility behavior for whole-card and memory-less requests to prevent incorrect placement decisions.
    • Preserved existing legacy workload behavior on nodes reserved for hami-core.
  • Tests
    • Expanded core-mode gating tests with additional whole-card and memory-less scenarios, including negative cases and regression/positive coverage for reserved-node compatibility.

…ssing the node mode gate

The node soft/hard exclusivity added in Project-HAMi#1812 rejects a mismatched pod with
ModeNotFit, but the check is nested inside
`request.Memreq > 0 && request.Memreq < totalMemPerCard && request.Nums > 0`.
A whole-card memory request (Memreq == card capacity) or a memory-less request
(Memreq == 0) never enters that block, so a hami-core (soft-split) pod can be
scheduled onto a hard-split node, bypassing the exclusivity.

Lift the soft-pod arm out of the memory-range condition: a pod that declares
hami-core mode must land on a hami-core node regardless of how much memory it
requests. The reverse arm (a legacy pod on a hami-core reserved node) stays
inside the memory-range condition on purpose, so plain whole-card jobs are not
rejected when a node -- or the global hamiVnpuCore default -- marks the node as
hami-core.

Verified on real hardware (8x Ascend 910B4): a hami-core pod requesting the
whole card (32768 MiB) or no memory field is now held Pending with ModeNotFit
on a hard node, matching the sub-capacity behaviour, while matching-mode and
whole-card legacy requests keep scheduling.

Signed-off-by: wangmin <wangmin@riseunion.io>
@hami-robot
hami-robot Bot requested review from archlitchi and wawa0210 July 8, 2026 00:52
@github-actions github-actions Bot added the kind/bug Something isn't working label Jul 8, 2026
@hami-robot hami-robot Bot added the size/L label Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 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: 95766056-57e9-4306-8a9b-657c579ed8ea

📥 Commits

Reviewing files that changed from the base of the PR and between d5dc085 and 6c508a8.

📒 Files selected for processing (2)
  • pkg/device/ascend/device.go
  • pkg/device/ascend/device_test.go
💤 Files with no reviewable changes (2)
  • pkg/device/ascend/device.go
  • pkg/device/ascend/device_test.go

📝 Walkthrough

Walkthrough

The Ascend Fit logic now rejects hami-core pods on nodes without hami-core support before the memory-based gate, and the test table adds whole-card and memory-less cases to cover the updated mode checks.

Changes

Ascend hami-core mode gate fix

Layer / File(s) Summary
Early hami-core node-support guard in Fit
pkg/device/ascend/device.go
Fit now immediately rejects a hami-core pod when the node does not support hami-core, moved outside the memory-range (Memreq/Nums) gated block; the legacy vNPU rejection remains under the original gated condition.
Mode gate test coverage
pkg/device/ascend/device_test.go
New TestDevices_Fit cases assert ModeNotFit for hami-core pods on legacy nodes with whole-card or zero memory requests, and confirm successful fits for matching-mode whole-card and legacy whole-card scenarios.

Estimated code review effort: 2 (Simple) | ~15 minutes

Poem

A rabbit hopped through checks so neat,
A full-card gap got tucked away from heat.
Soft and hard now meet their proper gate,
And tests agree the fit is straight. 🐇

🚥 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 summarizes the main fix: preventing hami-core requests from bypassing the node mode gate.
Linked Issues check ✅ Passed The code moves the hami-core rejection outside the memory-range gate and adds tests for the whole-card and memory-less cases described in #2028.
Out of Scope Changes check ✅ Passed The changes stay focused on the Ascend mode-gating bug and its test coverage, with no明显 unrelated code paths introduced.
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

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

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request ensures that hami-core pods are correctly restricted to hami-core nodes regardless of their memory requests (including whole-card and memory-less requests) by moving the node compatibility check outside of the memory-range condition. Corresponding unit tests were added to verify these scenarios. Feedback was provided regarding a potential nil pointer dereference when logging nodeInfo.Node.Name and pod.Name in the legacy vNPU filtering block, which could lead to runtime panics.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/device/ascend/device.go
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 59.55% <100.00%> (+0.03%) ⬆️

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

Files with missing lines Coverage Δ
pkg/device/ascend/device.go 83.68% <100.00%> (+0.46%) ⬆️

... and 2 files with indirect coverage changes

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

Use klog.KObj(pod) instead of dereferencing nodeInfo.Node.Name and
pod.Name directly, matching the hami-core arm above and avoiding a
potential nil dereference (both are guarded as possibly nil earlier in
Fit).

Signed-off-by: wangmin <wangmin@riseunion.io>

@DSFans2014 DSFans2014 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

@ouyangluwei163 ouyangluwei163 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 remove the AI-generated code comments and follow the new specification #1998

Comment thread pkg/device/ascend/device.go Outdated
Comment thread pkg/device/ascend/device.go Outdated
Signed-off-by: wangmin <wangmin@riseunion.io>
@hami-robot hami-robot Bot added size/M and removed lgtm size/L labels Jul 8, 2026
@Wangmin362

Copy link
Copy Markdown
Member Author

Please remove the AI-generated code comments and follow the new specification #1998

done,

Please remove the AI-generated code comments and follow the new specification #1998

done, I have removed the redundant comments.

@Wangmin362
Wangmin362 force-pushed the fix/ascend-hamicore-wholecard-mode-gate branch from 6c508a8 to cdbaaae Compare July 8, 2026 09:47

@ouyangluwei163 ouyangluwei163 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.

/lgtm

@archlitchi archlitchi 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 Jul 9, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: archlitchi, ouyangluwei163, Wangmin362

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

@hami-robot hami-robot Bot added the approved label Jul 9, 2026
@hami-robot
hami-robot Bot merged commit 3412885 into Project-HAMi:master Jul 9, 2026
14 checks passed
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.

[Ascend] whole-card / memory-less hami-core (soft-split) requests bypass the node soft/hard mode gate (#1812)

4 participants