Skip to content

fix (ascend) - validate module pair count and prevent under allocation for ascend 910C - #2369

Merged
hami-robot[bot] merged 6 commits into
Project-HAMi:masterfrom
princexpoddar:fix/ascend-910c-module-pairing
Aug 6, 2026
Merged

fix (ascend) - validate module pair count and prevent under allocation for ascend 910C#2369
hami-robot[bot] merged 6 commits into
Project-HAMi:masterfrom
princexpoddar:fix/ascend-910c-module-pairing

Conversation

@princexpoddar

@princexpoddar princexpoddar commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:
while going through ascend 910c device allocation logic in pkg/device/ascend/device.go...I found a issue in how multi NPU requests are validated during scheduling:
-when a pod requested multiple NPUs ( lets say 4 NPUs) on a node with 1 full card pair(2 NPUs) and other partial single NPU available... computeBestCombination910C filtered out partial cards and returned only the full pair found(2NPUs) and fit() assigned this result to tmpDevs and unconditionally returned true,thus causing under allocation of 2NPUs for a 4 NPU request while reporting success
-when the raw candidature NPU count happened to equal originReq (lets say asking for 2 NPUs on a node with 2 available NPUs on separate cards), Fit() returned true early without invoking computeBestCombination910C() whenever needTopology was false or NetworkID was missing..thus allowing candidate NPUs on separate cards to bypass module pairing validation completely
-In computeBestCombination910C() cards were sorted in ascending order by available NPU count which contradicted the comment directly above it stating full cards should be preferred first

To resolve these,
I have updated Fit() to verify that len(combination) == int(originReq) after module filtering and if sufficient complete module pairs cannot satsfy the request it now returns fit=false with AllocatedCardsInsufficientRequest instead of reporting success on a partial allocation

Also ensured module-pair validation always runs for multi-device Ascend910CType requests regardless of whether NetworkID is present

Updated common.GenReason parameter passing and failure tracking so Kubernetes logs and reason strings accurately report requested versus allocated NPU counts.

Changed card sorting in computeBestCombination910C() to descending order so fully available cards are evaluated before partially available ones.

Added regression tests in pkg/device/ascend/device_910c_pairing_test.go covering
-partial allocation rejection (TestAscend910C_FitPartialAllocationBug)
-candidate-count bypass prevention (TestAscend910C_FitExactCountBypassBug)
-successful full-pair allocation (TestAscend910C_FitFullPairSucceeds)
-missing NetworkID handling (TestAscend910C_FitWithoutNetworkID_ValidatesPairing)
-empty combination handling when no candidate NPUs form a complete module (TestComputeBestCombination910C_NoFullPairsReturnsEmpty).

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

Special notes for your reviewer:

  • go test -v ./pkg/device/ascend/.... All unit tests pass cleanly.
  • updated unit tests to explicitly set Health =true to align with the recently merged upstream health checks (fix(ascend): skip unhealthy devices in Fit() #2241)
  • AI assistance - Used Claude assistance

Does this PR introduce a user-facing change?:
No

Summary by CodeRabbit

  • Bug Fixes

    • Improved Ascend 910C allocation to require complete two-NPU module pairs.
    • Prevented partial or insufficient allocations, including when topology information is unavailable.
    • Prioritized cards with more available NPUs while maintaining valid pairing requirements.
  • Tests

    • Added regression coverage for partial allocations, exact-count requests, missing network metadata, valid pair allocation, and unavailable complete pairs.

…for Ascend 910C

Signed-off-by: Prabal Poddar <prabalpoddar73@gmail.com>
… fix reason reporting

Always run computeBestCombination910C for multi-device Ascend 910C requests even when NetworkID is absent or needTopology is false. Update AllocatedCardsInsufficientRequest reason to report the selected NPU count and pass originReq to GenReason.

Signed-off-by: Prabal Poddar <prabalpoddar73@gmail.com>
Verify that computeBestCombination910C returns empty slice and Fit returns fit=false when no candidate NPUs share a full module and NetworkID is absent.

Signed-off-by: Prabal Poddar <prabalpoddar73@gmail.com>
Signed-off-by: Prabal Poddar <prabalpoddar73@gmail.com>
@hami-robot hami-robot Bot added kind/bug Something isn't working dco-signoff: yes labels Aug 4, 2026
@hami-robot hami-robot Bot added the size/L label Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 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: 4302dd1f-2aaf-4d2d-b237-f14806b1d013

📥 Commits

Reviewing files that changed from the base of the PR and between 6fa265b and a4ef56c.

📒 Files selected for processing (2)
  • pkg/device/ascend/device.go
  • pkg/device/ascend/device_910c_pairing_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/device/ascend/device_910c_pairing_test.go
  • pkg/device/ascend/device.go

📝 Walkthrough

Walkthrough

This PR enforces complete module-pair allocation for multi-device Ascend 910C requests. It rejects short selections, validates exact-count candidates, updates card sorting, and adds regression tests for pairing metadata and no-pair cases.

Changes

Ascend 910C Pairing Fix

Layer / File(s) Summary
Module-pair enforcement and card ordering
pkg/device/ascend/device.go
Multi-device Ascend910C requests always use module-pair selection. Fit() rejects incomplete selections with AllocatedCardsInsufficientRequest. Topology-aware selection uses computeBestCombination, and card groups sort by descending available NPU count.
Regression tests for pairing validation
pkg/device/ascend/device_910c_pairing_test.go
Tests cover under-allocation rejection, exact-count candidate validation, valid full-pair allocation, missing NetworkID metadata, and no complete pair results.

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

Possibly related PRs

  • Project-HAMi/HAMi#2270: Modifies the same Ascend 910C allocation and pairing logic and adds related regression tests.

Suggested reviewers: chaunceyjiang

Poem

A rabbit pairs the cards just right,
Two NPUs make the module bright.
Short selections now must cease,
Full pairs pass the allocation test.
Hop, hop, the modules align! 🐇

🚥 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 Ascend 910C module-pair validation and under-allocation fix.
Linked Issues check ✅ Passed The changes address all requirements in issue #2268, including pairing validation, exact allocation counts, fallback handling, sorting, and regression tests.
Out of Scope Changes check ✅ Passed The changes are limited to Ascend 910C allocation logic and directly related regression tests.
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

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.

🧹 Nitpick comments (1)
pkg/device/ascend/device_910c_pairing_test.go (1)

56-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the insufficient-allocation reason.

This test only asserts fit == false. It passes if Fit returns a different failure reason or an empty reason. Assert that reason contains common.AllocatedCardsInsufficientRequest.

Proposed test update
 import (
+	"strings"
 	"testing"

 	corev1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

 	"github.com/Project-HAMi/HAMi/pkg/device"
+	"github.com/Project-HAMi/HAMi/pkg/device/common"
 )
@@
 	if fit {
 		t.Errorf("expected fit=false when only 2 of 4 requested NPUs form full module pairs, got fit=true, allocated=%d, reason=%q",
 			len(tmpDevs[Ascend910CType]), reason)
 	}
+	if !strings.Contains(reason, common.AllocatedCardsInsufficientRequest) {
+		t.Errorf("expected reason to contain %q, got %q", common.AllocatedCardsInsufficientRequest, reason)
+	}
🤖 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_910c_pairing_test.go` around lines 56 - 61, Update
the failure assertions in the test around dev.Fit to also verify that reason
contains common.AllocatedCardsInsufficientRequest, while preserving the existing
fit=false and allocation checks.
🤖 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 `@pkg/device/ascend/device_910c_pairing_test.go`:
- Around line 56-61: Update the failure assertions in the test around dev.Fit to
also verify that reason contains common.AllocatedCardsInsufficientRequest, while
preserving the existing fit=false and allocation checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f6408c61-bf15-453b-9cba-ce58d597555c

📥 Commits

Reviewing files that changed from the base of the PR and between 2cabe29 and f4f05ff.

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

Apply De Morgan's law to QF1001 staticcheck findings in Fit().
Add AllocatedCardsInsufficientRequest reason checks to 910C pairing tests.

Signed-off-by: Prabal Poddar <prabalpoddar73@gmail.com>
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 62.38% <100.00%> (+1.37%) ⬆️

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 84.68% <100.00%> (+1.15%) ⬆️

... and 20 files with indirect coverage changes

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

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

Copy link
Copy Markdown
Member

/assign

…nd tests

Signed-off-by: Prabal Poddar <prabalpoddar73@gmail.com>

@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 added the lgtm label Aug 6, 2026
@hami-robot

hami-robot Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 Aug 6, 2026
@hami-robot
hami-robot Bot merged commit dbc8d23 into Project-HAMi:master Aug 6, 2026
16 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.

silent under-allocation and topology bypass in Ascend 910C device allocation

2 participants