Skip to content

feat(ascend): support 910C vNPU templates vir05_1c_16g and vir10_3c_32g#2005

Open
ouyangluwei163 wants to merge 1 commit into
Project-HAMi:masterfrom
ouyangluwei163:feat/ascend-910c-vnpu-templates
Open

feat(ascend): support 910C vNPU templates vir05_1c_16g and vir10_3c_32g#2005
ouyangluwei163 wants to merge 1 commit into
Project-HAMi:masterfrom
ouyangluwei163:feat/ascend-910c-vnpu-templates

Conversation

@ouyangluwei163

@ouyangluwei163 ouyangluwei163 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Ascend HDK 26.0.RC1 enables NPU virtualization (vNPU) on the 910C. The 910C was previously registered without any vNPU templates, so it could only be allocated as a whole card and fractional (memory/core) requests could not be scheduled.

Add the vir05_1c_16g (16GB/5 aiCore/1 aiCPU) and vir10_3c_32g (32GB/10 aiCore/3 aiCPU) templates to the scheduler device config, and add examples/ascend/job-910C.yaml demonstrating a vNPU request.

What type of PR is this?
/kind feature

What this PR does / why we need it:

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

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Summary by CodeRabbit

  • New Features
    • Added new VNPU template options for Ascend910C, including additional memory and compute profiles.
    • Added a new Kubernetes example Pod manifest showing how to request a specific Ascend910C resource and memory allocation.

Ascend HDK 26.0.RC1 enables NPU virtualization (vNPU) on the 910C. The
910C was previously registered without any vNPU templates, so it could
only be allocated as a whole card and fractional (memory/core) requests
could not be scheduled.

Add the vir05_1c_16g (16GB/5 aiCore/1 aiCPU) and vir10_3c_32g
(32GB/10 aiCore/3 aiCPU) templates to the scheduler device config, and
add examples/ascend/job-910C.yaml demonstrating a vNPU request.

Signed-off-by: ouyangluwei(riseunion) <ouyangluwei@riseunion.io>
@hami-robot hami-robot Bot requested review from FouoF and mesutoezdil July 3, 2026 07:54
@hami-robot

hami-robot Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ouyangluwei163
Once this PR has been reviewed and has the lgtm label, please assign wawa0210 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 size/S label Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds vir05_1c_16g and vir10_3c_32g vNPU template definitions (memory, aiCore, aiCPU) to the Ascend910 chip entry in the scheduler's device-configmap.yaml, and adds a new example Pod manifest demonstrating a fractional Ascend910C resource request.

Changes

Ascend 910C vNPU Template Support

Layer / File(s) Summary
vNPU template definitions
charts/hami/templates/scheduler/device-configmap.yaml
Adds a templates block under Ascend910's vnpus config defining vir05_1c_16g and vir10_3c_32g with memory, aiCore, and aiCPU values.
Example Pod using vNPU template
examples/ascend/job-910C.yaml
Adds a new Pod manifest requesting huawei.com/Ascend910C and huawei.com/Ascend910C-memory resources mapped to a vNPU template.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Poem

Two new slices of NPU pie,
vir05, vir10, oh my!
A pod hops in, sleeps a day,
Sharing cores the vNPU way.
🐇✨ Hop, allocate, and fly!

🚥 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 matches the main change: adding Ascend 910C vNPU template support.
Linked Issues check ✅ Passed The PR adds the two requested 910C templates and a usage example, matching issue #2004's expected behavior.
Out of Scope Changes check ✅ Passed The example Pod manifest is directly related to the new 910C vNPU support and no unrelated changes are evident.
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 adds vNPU templates for Ascend devices in the scheduler configuration and provides an example job configuration for Ascend910C. Feedback points out a critical bug where vNPU requests for Ascend910C are incorrectly rounded up to 2 NPUs during admission mutation, and suggests code modifications to bypass this rounding and adjust the scheduling logic for fractional vNPU requests.

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 on lines +12 to +16
huawei.com/Ascend910C: 1 # requesting 1 NPU
# requesting device memory; the value maps to a vNPU template (Ascend HDK 26.0.RC1):
# 16384 -> vir05_1c_16g (16GB, 5 aiCore, 1 aiCPU)
# 32768 -> vir10_3c_32g (32GB, 10 aiCore, 3 aiCPU)
huawei.com/Ascend910C-memory: 16384

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.

high

There is a critical bug in pkg/device/ascend/device.go's MutateAdmission function that will cause this example job (and any Ascend910C vNPU request) to be mutated to request 2 NPUs instead of 1 NPU.

Why this happens

In MutateAdmission (lines 134-149), the code unconditionally rounds up any Ascend910C request of 1 to 2 because the minimum allocation unit for a whole card is 2 NPUs:

	if dev.config.CommonWord == Ascend910CType {
		if reqNum == 1 {
			// Since the minimum allocation unit is one physical module (2 NPUs), round up the limits and requests to 2.
			klog.InfoS("Adjusted Ascend910C device request from 1 to 2 (minimum allocation unit)", "pod", klog.KObj(p))
			reqNum = 2
            ...

However, for a vNPU request (where memory or core limits are specified), the user is requesting a fractional slice of a single NPU. Rounding this up to 2 NPUs is incorrect and will result in the scheduler allocating 2 separate NPUs, each with the requested memory, or failing to schedule if resources are tight.

How to fix it

  1. In pkg/device/ascend/device.go's MutateAdmission function, check if it is a vNPU request and skip the rounding up logic:
	_, hasMemory := ctr.Resources.Limits[corev1.ResourceName(dev.config.ResourceMemoryName)]
	if !hasMemory {
		_, hasMemory = ctr.Resources.Requests[corev1.ResourceName(dev.config.ResourceMemoryName)]
	}
	_, hasCore := ctr.Resources.Limits[corev1.ResourceName(dev.config.ResourceCoreName)]
	if !hasCore {
		_, hasCore = ctr.Resources.Requests[corev1.ResourceName(dev.config.ResourceCoreName)]
	}
	isVnpuRequest := hasMemory || hasCore

	if dev.config.CommonWord == Ascend910CType && !isVnpuRequest {
		if reqNum == 1 {
			// Since the minimum allocation unit is one physical module (2 NPUs), round up the limits and requests to 2.
			klog.InfoS("Adjusted Ascend910C device request from 1 to 2 (minimum allocation unit)", "pod", klog.KObj(p))
			reqNum = 2
			ctr.Resources.Limits[corev1.ResourceName(dev.config.ResourceName)] = *resource.NewQuantity(reqNum, resource.DecimalExponent)
			if _, exists := ctr.Resources.Requests[corev1.ResourceName(dev.config.ResourceName)]; exists {
				ctr.Resources.Requests[corev1.ResourceName(dev.config.ResourceName)] = *resource.NewQuantity(reqNum, resource.DecimalExponent)
			}
		} else if reqNum%2 != 0 {
			// Reject any other odd-numbered request (e.g., 3, 5, 7...)
			errMsg := fmt.Sprintf("Ascend910C device request must be 1 or 2*n, got %d", reqNum)
			klog.ErrorS(nil, errMsg, "pod", klog.KObj(p))
			return false, errors.New(errMsg)
		}
	}
  1. In pkg/device/ascend/device.go's Fit function, only use computeBestCombination910C (which strictly requires full cards with both NPUs available) for whole-card requests. For vNPU requests, use the standard computeBestCombination so that vNPUs can be scheduled on partially-allocated cards:
				isVnpuRequest := (k.Memreq > 0 && k.Memreq < totalMemPerCard) || (k.Coresreq > 0 && k.Coresreq < 100)
				if k.Type == Ascend910CType && !isVnpuRequest {
					// Use topology-aware allocation for Ascend910C: only select full modules (2 NPUs per card).
					combination = npu.computeBestCombination910C(nodeInfo, int(originReq), tmpDevs[k.Type])
				} else {
					combination = npu.computeBestCombination(nodeInfo, int(originReq), tmpDevs[k.Type])
				}

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

🧹 Nitpick comments (2)
examples/ascend/job-910C.yaml (2)

12-16: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Comment "requesting 1 NPU" is misleading given auto-adjustment behavior.

Per pkg/device/ascend/device.go MutateAdmission, when commonWord == Ascend910CType and the request is 1, HAMi silently rounds it up to 2 (minimum allocation unit is one physical module = 2 NPUs). The example's comment says "requesting 1 NPU" without mentioning this auto-adjustment, which could confuse users about the actual resulting allocation.

📝 Suggested comment clarification
-          huawei.com/Ascend910C: 1 # requesting 1 NPU
+          huawei.com/Ascend910C: 1 # requesting 1 NPU (auto-adjusted to 2, the minimum allocation unit)
🤖 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 `@examples/ascend/job-910C.yaml` around lines 12 - 16, Update the example
comment in the Ascend 910C job manifest so it reflects the behavior in
MutateAdmission for Ascend910CType: a request of 1 is automatically rounded up
to 2 NPUs. Clarify the note near the huawei.com/Ascend910C resource to mention
the minimum physical module allocation and that the scheduler will adjust the
request, so users understand the actual allocated count.

1-16: 🔒 Security & Privacy | 🔵 Trivial | 💤 Low value

Static analysis flags root/privilege-escalation defaults on example manifest.

Checkov flags missing allowPrivilegeEscalation: false and non-root securityContext (CKV_K8S_20, CKV_K8S_23). Since this is a demo/example manifest, this is low priority, but adding a minimal securityContext would align with security best practices for example docs that users may copy verbatim.

🤖 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 `@examples/ascend/job-910C.yaml` around lines 1 - 16, The example Pod manifest
is missing the basic container hardening settings flagged by Checkov. Update the
ubuntu-container spec to include a minimal securityContext with
allowPrivilegeEscalation set to false and runAsNonRoot enabled (and, if needed,
a non-root runAsUser) so the example aligns with safer defaults while keeping
the existing Pod and resources fields intact.

Source: Linters/SAST tools

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

Nitpick comments:
In `@examples/ascend/job-910C.yaml`:
- Around line 12-16: Update the example comment in the Ascend 910C job manifest
so it reflects the behavior in MutateAdmission for Ascend910CType: a request of
1 is automatically rounded up to 2 NPUs. Clarify the note near the
huawei.com/Ascend910C resource to mention the minimum physical module allocation
and that the scheduler will adjust the request, so users understand the actual
allocated count.
- Around line 1-16: The example Pod manifest is missing the basic container
hardening settings flagged by Checkov. Update the ubuntu-container spec to
include a minimal securityContext with allowPrivilegeEscalation set to false and
runAsNonRoot enabled (and, if needed, a non-root runAsUser) so the example
aligns with safer defaults while keeping the existing Pod and resources fields
intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 014964da-43df-4e85-8dfe-f8e1bede193f

📥 Commits

Reviewing files that changed from the base of the PR and between 430b458 and 3b835f5.

📒 Files selected for processing (2)
  • charts/hami/templates/scheduler/device-configmap.yaml
  • examples/ascend/job-910C.yaml

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 59.09% <ø> (ø)

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

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

command: ["bash", "-c", "sleep 86400"]
resources:
limits:
huawei.com/Ascend910C: 1 # requesting 1 NPU

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.

@ouyangluwei163 Before lgtm, one question: issue #2004 says "a single Ascend 910C NPU can be sliced into smaller compute instances", but MutateAdmission unconditionally bumps Ascend910C: 1 to 2. For a vNPU request like this one, GenerateResourceRequests reads the bumped limit (2), Fit allocates 2 physical NPUs each with vir05_1c_16g, and the container gets 2 vNPU instances consuming 32768 MB total, not 1. Should the bump be skipped when memory is specified, so a single-NPU vNPU slice works as described in the issue?

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(ascend): support 910C vNPU templates vir05_1c_16g and vir10_3c_32g (Ascend HDK 26.0.RC1)

2 participants