Skip to content

fix(awsneuron): allocate by device index, not slice position - #2960

Open
mesutoezdil wants to merge 2 commits into
Project-HAMi:masterfrom
mesutoezdil:fix/awsneuron-allocate-by-index
Open

fix(awsneuron): allocate by device index, not slice position#2960
mesutoezdil wants to merge 2 commits into
Project-HAMi:masterfrom
mesutoezdil:fix/awsneuron-allocate-by-index

Conversation

@mesutoezdil

@mesutoezdil mesutoezdil commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

continuousDeviceAvailable collected slice positions while Fit matched those values against DeviceUsage.Index, and the two agree only when the slice is in index order, which it is not because the scheduler sorts devices by score first. On a node whose device 5 is busy the sorted order starts [5 0 1 2 3 4 6 7 ...], so a four device request returns positions [4 5 6 7] and Fit reads them as indexes and allocates index 5, which is already in use.

@hami-robot

hami-robot Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mesutoezdil
Once this PR has been reviewed and has the lgtm label, please assign archlitchi 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

@mesutoezdil

Copy link
Copy Markdown
Contributor Author

/kind bug

@hami-robot hami-robot Bot added the kind/bug Something isn't working label Sep 2, 2026
@coderabbitai

coderabbitai Bot commented Sep 2, 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: Team

Run ID: afc70d2e-707e-4b1d-aa13-95d24bcb715e

📥 Commits

Reviewing files that changed from the base of the PR and between 56b3b47 and 1983f62.

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

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Neuron device selection

Layer / File(s) Summary
Physical index alignment
pkg/device/awsneuron/device.go, pkg/device/awsneuron/device_test.go
continuousDeviceAvailable returns physical device indexes. graphSelect sorts devices by index before adjacency grouping. Tests cover score-sorted input, busy devices, offset indexes, and node-type lookup.

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

Merge Risk: ⚪ Minimal · up to 06b76

This localized fix makes AWS Neuron allocation use physical device indexes, preventing reordered device lists from selecting an already-busy device. No actionable merge-blocking risk remains after normal checks and review.

Poem

A rabbit checks the neuron row
Physical indexes guide the flow
Busy devices stay apart
Free neighbors form the right start
Tests verify each hopping part

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: AWS Neuron allocation now uses device indexes instead of slice positions.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 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.

continuousDeviceAvailable collected slice positions, and Fit matched
those values against DeviceUsage.Index. The two agree only while the
slice happens to be in index order, and it is not: score.go sorts the
device list before calling Fit.

On a node whose device 5 is busy, the sorted order starts [5 0 1 2 3 4
6 7 ...]. Asking for four devices returns positions [4 5 6 7], which
hold the free indexes 3, 4, 6 and 7, but Fit reads them as indexes 4,
5, 6 and 7 and allocates index 5, which is already in use.

Return indexes from continuousDeviceAvailable and order a copy of the
slice by index in graphSelect, so adjacency is still read from the
physical layout. kunlun's topology selector already does this and says
why in its own comment. Sorting first also puts the device carrying the
node type back at position zero, where graphSelect looks for it.

Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
The first round only guarded the ordering change: the shared test helper
builds Index equal to slice position, so reverting the index change alone
left every test passing.

Add cases built on an index set that does not start at zero, where a
result made of positions is distinguishable from one made of indexes, and
a case where only the lowest-index device carries the node type, which is
what the reordered lookup depends on. Reverting either half of the fix
now fails a test.

Also switch the comparator to cmp.Compare, since Index is unsigned and
subtracting two converted values is a pattern worth avoiding.

Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
@mesutoezdil
mesutoezdil force-pushed the fix/awsneuron-allocate-by-index branch from 1983f62 to 06b76d8 Compare September 3, 2026 12:10
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/device/awsneuron/device.go 88.88% 1 Missing ⚠️
Flag Coverage Δ
unittests 70.87% <88.88%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
pkg/device/awsneuron/device.go 86.07% <88.88%> (-0.01%) ⬇️

... and 1 file with indirect coverage changes

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant