Skip to content

Follow node vNPU mode for pods without vnpu-mode annotation#106

Open
ouyangluwei163 wants to merge 2 commits into
Project-HAMi:mainfrom
ouyangluwei163:feat/mode-follows-node-v2
Open

Follow node vNPU mode for pods without vnpu-mode annotation#106
ouyangluwei163 wants to merge 2 commits into
Project-HAMi:mainfrom
ouyangluwei163:feat/mode-follows-node-v2

Conversation

@ouyangluwei163

@ouyangluwei163 ouyangluwei163 commented Jul 9, 2026

Copy link
Copy Markdown

HAMi: Project-HAMi/HAMi#2034
fix: #105

Summary by CodeRabbit

  • Documentation
    • Updated “Usage in HAMi” to clarify effective mode selection: pods with huawei.com/vnpu-mode: hami-core always use soft slicing and schedule only to compatible nodes; pods without the annotation follow the node’s capabilities.
  • Bug Fixes
    • Improved device allocation so pods with no VNPUMode annotation correctly follow the node’s HAMi-core vs template behavior.
  • Tests
    • Added coverage for allocation outcomes when the pod omits the mode annotation under both node types.

@coderabbitai

coderabbitai Bot commented Jul 9, 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: 133dac4a-a46f-4cbf-a2dc-54fa3886d856

📥 Commits

Reviewing files that changed from the base of the PR and between cdd7076 and 2a02ef3.

📒 Files selected for processing (3)
  • README.md
  • internal/server/allocate.go
  • internal/server/util_test.go
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/server/allocate.go
  • internal/server/util_test.go

📝 Walkthrough

Walkthrough

The device plugin now resolves allocation mode for annotation-less pods from the node’s IsHamiVnpuCore() setting, while annotated pods keep their pinned Hami-core path. Tests and README text were updated to match the new mode selection.

Changes

Mode-agnostic vNPU resolution

Layer / File(s) Summary
Effective HAMi-core decision logic
internal/server/allocate.go
buildContainerAllocateResponse treats a pod as HAMi-core when vnpuMode is explicitly VNPUModeHamiCore or unset with node IsHamiVnpuCore() true; debug log now reports raw mode and computed effective value.
Tests for node-driven mode fallback
internal/server/util_test.go
Two new table-driven cases simulate empty pod annotations with node core mode true/false, asserting env vars and mounts differ per resolved mode.
README documentation update
README.md
Usage in HAMi text now states annotated pods always use soft slicing while annotation-less pods follow the node's hami-vnpu-core setting.

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

Possibly related issues

Possibly related PRs

Suggested labels: lgtm, approved

Suggested reviewers: archlitchi

Poem

A pod with no label, but no need to fret,
The node whispers softly which mode to set,
Hami-core hopping, or template instead,
No more stuck Pending, no more dread,
Hop, hop, hooray — the vNPU's well-fed! 🐰🥕

🚥 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 the main behavior change for pods without vnpu-mode annotation.
Linked Issues check ✅ Passed The code and tests implement node-derived mode selection for annotation-less pods and keep explicitly pinned modes unchanged.
Out of Scope Changes check ✅ Passed The README update, logic change, and tests are all directly aligned with the linked issue.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 `@internal/server/util_test.go`:
- Around line 449-465: The hami-core allocation test expectation is missing the
per-container shared-memory mount, so the mount count assertion will fail.
Update the `buildContainerAllocateResponseWant` setup in
`internal/server/util_test.go` for this case to include the extra mount appended
by the `HamiCoreMode_Mounts` path (the per-container `hostHookPath +
"/containers/_"` shmem dir) so `resp.Mounts` matches `tc.want.mounts`. Keep the
existing `mounts` slice in sync with the behavior exercised by
`buildContainerAllocateResponse` and `HamiCoreMode_Mounts`.
🪄 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: 9d95ce2f-6c0b-46bc-b45e-bf15bfcadc18

📥 Commits

Reviewing files that changed from the base of the PR and between 15f0d4a and cdd7076.

📒 Files selected for processing (3)
  • README.md
  • internal/server/allocate.go
  • internal/server/util_test.go

Comment on lines +449 to +465
want: buildContainerAllocateResponseWant{
envs: map[string]string{
"ASCEND_VISIBLE_DEVICES": "3",
"NPU_MEM_QUOTA": "8738",
"NPU_PRIORITY": "4",
"NPU_GLOBAL_SHM_PATH": "/hami-shared-region/3_global_registry",
},
mounts: []*v1beta1.Mount{
{HostPath: "/usr/local/bin/npu-smi", ContainerPath: "/usr/local/bin/npu-smi", ReadOnly: true},
{HostPath: "/etc/ascend_install.info", ContainerPath: "/etc/ascend_install.info", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/lib64/driver", ContainerPath: "/usr/local/Ascend/driver/lib64/driver", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/version.info", ContainerPath: "/usr/local/Ascend/driver/version.info", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core", ContainerPath: "/hami-vnpu-core", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core/ld.so.preload", ContainerPath: "/etc/ld.so.preload", ReadOnly: true},
{HostPath: "/usr/local/hami-shared-region", ContainerPath: "/hami-shared-region", ReadOnly: false},
},
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Missing mount entry — test will fail.

want.mounts lists only 7 entries, but the hami-core branch always appends an 8th mount for the per-container shmem dir (hostHookPath + "/containers/_", per the existing HamiCoreMode_Mounts case). The len(resp.Mounts) != len(tc.want.mounts) check will fail this subtest.

🐛 Proposed fix
 				mounts: []*v1beta1.Mount{
 					{HostPath: "/usr/local/bin/npu-smi", ContainerPath: "/usr/local/bin/npu-smi", ReadOnly: true},
 					{HostPath: "/etc/ascend_install.info", ContainerPath: "/etc/ascend_install.info", ReadOnly: true},
 					{HostPath: "/usr/local/Ascend/driver/lib64/driver", ContainerPath: "/usr/local/Ascend/driver/lib64/driver", ReadOnly: true},
 					{HostPath: "/usr/local/Ascend/driver/version.info", ContainerPath: "/usr/local/Ascend/driver/version.info", ReadOnly: true},
 					{HostPath: "/usr/local/hami-vnpu-core", ContainerPath: "/hami-vnpu-core", ReadOnly: true},
 					{HostPath: "/usr/local/hami-vnpu-core/ld.so.preload", ContainerPath: "/etc/ld.so.preload", ReadOnly: true},
 					{HostPath: "/usr/local/hami-shared-region", ContainerPath: "/hami-shared-region", ReadOnly: false},
+					{HostPath: hostHookPath + "/containers/_", ContainerPath: "/hami-vnpu-shmem", ReadOnly: false},
 				},
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
want: buildContainerAllocateResponseWant{
envs: map[string]string{
"ASCEND_VISIBLE_DEVICES": "3",
"NPU_MEM_QUOTA": "8738",
"NPU_PRIORITY": "4",
"NPU_GLOBAL_SHM_PATH": "/hami-shared-region/3_global_registry",
},
mounts: []*v1beta1.Mount{
{HostPath: "/usr/local/bin/npu-smi", ContainerPath: "/usr/local/bin/npu-smi", ReadOnly: true},
{HostPath: "/etc/ascend_install.info", ContainerPath: "/etc/ascend_install.info", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/lib64/driver", ContainerPath: "/usr/local/Ascend/driver/lib64/driver", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/version.info", ContainerPath: "/usr/local/Ascend/driver/version.info", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core", ContainerPath: "/hami-vnpu-core", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core/ld.so.preload", ContainerPath: "/etc/ld.so.preload", ReadOnly: true},
{HostPath: "/usr/local/hami-shared-region", ContainerPath: "/hami-shared-region", ReadOnly: false},
},
},
want: buildContainerAllocateResponseWant{
envs: map[string]string{
"ASCEND_VISIBLE_DEVICES": "3",
"NPU_MEM_QUOTA": "8738",
"NPU_PRIORITY": "4",
"NPU_GLOBAL_SHM_PATH": "/hami-shared-region/3_global_registry",
},
mounts: []*v1beta1.Mount{
{HostPath: "/usr/local/bin/npu-smi", ContainerPath: "/usr/local/bin/npu-smi", ReadOnly: true},
{HostPath: "/etc/ascend_install.info", ContainerPath: "/etc/ascend_install.info", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/lib64/driver", ContainerPath: "/usr/local/Ascend/driver/lib64/driver", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/version.info", ContainerPath: "/usr/local/Ascend/driver/version.info", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core", ContainerPath: "/hami-vnpu-core", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core/ld.so.preload", ContainerPath: "/etc/ld.so.preload", ReadOnly: true},
{HostPath: "/usr/local/hami-shared-region", ContainerPath: "/hami-shared-region", ReadOnly: false},
{HostPath: hostHookPath + "/containers/_", ContainerPath: "/hami-vnpu-shmem", ReadOnly: false},
},
},
🤖 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 `@internal/server/util_test.go` around lines 449 - 465, The hami-core
allocation test expectation is missing the per-container shared-memory mount, so
the mount count assertion will fail. Update the
`buildContainerAllocateResponseWant` setup in `internal/server/util_test.go` for
this case to include the extra mount appended by the `HamiCoreMode_Mounts` path
(the per-container `hostHookPath + "/containers/_"` shmem dir) so `resp.Mounts`
matches `tc.want.mounts`. Keep the existing `mounts` slice in sync with the
behavior exercised by `buildContainerAllocateResponse` and
`HamiCoreMode_Mounts`.

@hami-robot

hami-robot Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: 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

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

please fix the test case

ouyangluwei(riseunion) added 2 commits July 16, 2026 18:38
Signed-off-by: ouyangluwei(riseunion) <ouyangluwei@riseunion.io>
Signed-off-by: ouyangluwei(riseunion) <ouyangluwei@riseunion.io>
@ouyangluwei163
ouyangluwei163 force-pushed the feat/mode-follows-node-v2 branch from 2a02ef3 to f8848b2 Compare July 16, 2026 10:43
@hami-robot hami-robot Bot removed the lgtm label Jul 16, 2026
@hami-robot

hami-robot Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@maverick123123

Copy link
Copy Markdown
Contributor

LGTM on the logic. Please fix the test case as @DSFans2014 and CodeRabbit pointed out — the NoAnnotation_NodeHamiCore_FollowsNode test is missing the per-container shmem mount entry, so it will fail.

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.

Follow node vNPU mode for pods without vnpu-mode annotation

3 participants