Skip to content

Feat: Allow mode-agnostic Ascend pods to schedule across both vNPU-template and HAMi-core nodes - #2035

Merged
archlitchi merged 1 commit into
Project-HAMi:masterfrom
ouyangluwei163:feat/ascend-mode-follows-node
Aug 3, 2026
Merged

Feat: Allow mode-agnostic Ascend pods to schedule across both vNPU-template and HAMi-core nodes#2035
archlitchi merged 1 commit into
Project-HAMi:masterfrom
ouyangluwei163:feat/ascend-mode-follows-node

Conversation

@ouyangluwei163

@ouyangluwei163 ouyangluwei163 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind feature

What this PR does / why we need it:

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

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Summary by CodeRabbit

  • Bug Fixes
    • Device annotation generation now includes memory/core more reliably, including omitting the core field when the reported core count is zero.
    • Scheduling now rejects pods requesting hami-core immediately when the node can’t support it.
    • Removed legacy vNPU filtering that could incorrectly prevent compatible pods from fitting.
  • Tests
    • Updated unit tests to validate the new annotation payload rules and the revised hami-core fitting/admission behavior.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Ascend runtime annotations now include memory and core values for non-hami-core pods. Fit rejects unsupported hami-core requests early and allows annotation-less pods on supported hami-core nodes, with updated admission and fit tests.

Changes

Ascend mode-agnostic scheduling

Layer / File(s) Summary
RuntimeInfo annotation population
pkg/device/ascend/device.go, pkg/device/ascend/device_test.go
PatchAnnotations fills RuntimeInfo.Memory and Core for non-hami-core pods; tests cover populated values and omission of core when used cores are zero.
Fit mode compatibility
pkg/device/ascend/device.go, pkg/device/ascend/device_test.go
Fit immediately rejects unsupported hami-core requests and permits annotation-less pods on supported hami-core nodes; admission and fit expectations are updated.

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

Possibly related issues

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: lengrongfu, archlitchi

Poem

A rabbit checks the core and card,
While fitting pods is less hard.
Memory and cores join the chart,
Zero cores leave that field apart.
🐰 Modes now hop in harmony.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The scheduler and RuntimeInfo updates align with #2034, but the required self-detecting PostStart webhook hook is not shown in the changed files. Implement the webhook-side self-detecting PostStart hook that starts the limiter only when its binary exists, as required by #2034.
✅ Passed checks (4 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 feature: making Ascend pods mode-agnostic across vNPU-template and HAMi-core nodes.
Out of Scope Changes check ✅ Passed The diff stays focused on Ascend scheduling/runtime behavior and related tests; no unrelated changes are apparent.
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.

@hami-robot hami-robot Bot added the size/L label Jul 9, 2026
@coderabbitai coderabbitai Bot added the lgtm label Jul 9, 2026

@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 allows mode-agnostic (annotation-less) pods to be scheduled on hami-core nodes by removing the strict mode-fit filtering, and updates the container lifecycle injection to use a self-detecting PostStart hook. It also updates annotation patching to include memory and core allocations. The review feedback highlights a critical issue where setting info.Core to 0 for these mode-agnostic pods can prevent the limiter process from enforcing resource limits. It is recommended to fallback to the template's or device's default AICore value when Usedcores is 0, and to update the corresponding unit tests to assert this behavior.

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
Comment thread pkg/device/ascend/device_test.go

@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/device/ascend/device.go`:
- Around line 151-168: The new PostStart hook in device.go unconditionally uses
a sh-based ExecAction for Ascend containers, which can break shell-less or
distroless images when the limiter is absent. Update the hook logic around the
self-detecting hami-vnpu-core limiter injection so it is only added when the
container image can actually execute a shell, or replace the shell command with
a shell-free entrypoint; keep the no-op path safe by guarding the setup in the
same area that checks VNPUModeAnnotation, VNPUModeHamiCore, and
ctr.Lifecycle.PostStart.
🪄 Autofix (Beta)

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: 908a767d-51d0-409f-9840-e2d1adc16cfc

📥 Commits

Reviewing files that changed from the base of the PR and between 500fcef and 94d61e6.

📒 Files selected for processing (2)
  • pkg/device/ascend/device.go
  • pkg/device/ascend/device_test.go

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

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 60.14% <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.17% <100.00%> (-0.24%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@archlitchi

Copy link
Copy Markdown
Member

please resolve ai-comments and conflicts

Comment thread pkg/device/ascend/device.go Outdated
Comment thread pkg/device/ascend/device.go
@mesutoezdil

mesutoezdil commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

the branch is out of sync with current master.

also: line 185 in the PR branch has "vNPU nor supported for multiple devices" -- should be "not". this also confirms the branch needs a rebase.

the 'what this PR does / why we need it' section in the PR description is empty.

no ai assistance disclosure is present. if any ai tool was used, it must be disclosed per CONTRIBUTING.md: https://github.com/Project-HAMi/HAMi/blob/master/CONTRIBUTING.md#ai-assistance-notice

…te and HAMi-core nodes

Make an annotation-less Ascend pod mode-agnostic so its effective mode
follows the node it lands on, while pods pinned via huawei.com/vnpu-mode
keep today's behavior:

- Fit: only reject a hami-core-requested pod on a node that does not
  support it; unannotated (legacy vNPU) pods are allowed on both node
  types. Composes with the existing whole-card / memory-less mode gate.
- PatchAnnotations: emit a superset RuntimeInfo (template name plus raw
  memory/core) so the device plugin picks the right shape per node.

Limiter startup is no longer injected here: the scheduler-side PostStart
hook was removed upstream in Project-HAMi#2062, so this change is scheduling-only.

Fixes Project-HAMi#2034

Signed-off-by: ouyangluwei(riseunion) <ouyangluwei@riseunion.io>
@ouyangluwei163
ouyangluwei163 force-pushed the feat/ascend-mode-follows-node branch from a7c8881 to 73a86b3 Compare July 16, 2026 10:32
@ouyangluwei163
ouyangluwei163 marked this pull request as ready for review July 17, 2026 09:40
@hami-robot
hami-robot Bot requested a review from wawa0210 July 17, 2026 09:40

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/device/ascend/device_test.go (1)

915-946: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Missing self-detecting PostStart hook.

The PR objectives explicitly require injecting a "self-detecting PostStart hook that starts the limiter only when its binary is present". However, the AI summary and the updated test cases (expecting wantPostStart: false for hami-core) indicate that the PostStart lifecycle injection was completely removed from MutateAdmission instead of being updated.

If the injection was removed to bypass the previous review feedback regarding shell-less images, this leaves the limiter unstarted on hami-core nodes. Please restore the PostStart hook injection and update it to safely handle shell-less images (e.g., by using a shell-free entrypoint or checking for shell availability) to ensure the PR's core requirements are fulfilled.

🤖 Prompt for 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.

In `@pkg/device/ascend/device_test.go` around lines 915 - 946, Restore PostStart
lifecycle injection in MutateAdmission for hami-core containers, with
self-detection that starts the limiter only when its binary is present. Ensure
the hook remains safe for shell-less images by using a shell-independent
execution path or explicitly handling shell absence, and update the related test
expectation from wantPostStart false to the required injected-hook behavior.
🤖 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.

Outside diff comments:
In `@pkg/device/ascend/device_test.go`:
- Around line 915-946: Restore PostStart lifecycle injection in MutateAdmission
for hami-core containers, with self-detection that starts the limiter only when
its binary is present. Ensure the hook remains safe for shell-less images by
using a shell-independent execution path or explicitly handling shell absence,
and update the related test expectation from wantPostStart false to the required
injected-hook behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 06c32351-f07c-459b-a85a-77c92852068f

📥 Commits

Reviewing files that changed from the base of the PR and between a7c8881 and 73a86b3.

📒 Files selected for processing (2)
  • pkg/device/ascend/device.go
  • pkg/device/ascend/device_test.go

@ouyangluwei163

ouyangluwei163 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Two pods scheduled onto the same Ascend 910B4, both running the same continuous matmul load:

Pod A:
huawei.com/Ascend910B4: 1
huawei.com/Ascend910B4-memory: 16384
# no -core requested

Pod B :
huawei.com/Ascend910B4: 1
huawei.com/Ascend910B4-memory: 16384
huawei.com/Ascend910B4-core: 30

With both pods saturating the shared card (npu-smi AICore 100%), measured throughput is ~1:1 (~49 vs ~49
TFLOPS) instead of the expected ~1:30
image

Comment thread pkg/device/ascend/device.go

@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 Aug 3, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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.

Feat: Allow mode-agnostic Ascend pods to schedule across both vNPU-template and HAMi-core nodes

4 participants