Skip to content

Conversation

@wokalski
Copy link

@wokalski wokalski commented Nov 7, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:
This is a naive fix for CDI support.

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

Special notes for your reviewer:

I know this is wrong - i don't know how you determine CDI vs legacy container toolkit. I am happy to adjust it.

Does this PR introduce a user-facing change?:
Yes, it does. The goal is to properly support users that use the CDI.

@hami-robot hami-robot bot added kind/bug Something isn't working dco-signoff: no labels Nov 7, 2025
@hami-robot hami-robot bot requested review from Shouren and chaunceyjiang November 7, 2025 20:02
@hami-robot
Copy link
Contributor

hami-robot bot commented Nov 7, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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
Copy link
Contributor

hami-robot bot commented Nov 7, 2025

Welcome @wokalski! It looks like this is your first PR to Project-HAMi/HAMi 🎉

@github-actions github-actions bot removed the kind/bug Something isn't working label Nov 7, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @wokalski, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request provides an initial, acknowledged as 'naive,' solution to enhance support for the Container Device Interface (CDI) for NVIDIA devices. The core change involves adjusting how environment variables are formatted, specifically by adding a 'nvidia.com/gpu=' prefix to device ID strings. This modification ensures that CDI-enabled container runtimes can correctly interpret and utilize the NVIDIA devices, addressing a reported bug and improving the user experience for those leveraging CDI.

Highlights

  • CDI Support: Introduces a preliminary, or 'naive,' fix to enable better support for the Container Device Interface (CDI) within the NVIDIA device plugin.
  • Environment Variable Formatting: Modifies the apiEnvs function to prepend the string 'nvidia.com/gpu=' to the list of device IDs when constructing environment variables. This change is crucial for CDI compatibility.
  • User-Facing Change: This pull request is intended to be user-facing, aiming to properly support users who are utilizing CDI with NVIDIA devices.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@hami-robot hami-robot bot added the size/XS label Nov 7, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 attempts to fix CDI support by modifying the NVIDIA_VISIBLE_DEVICES environment variable. While the intent is good, the implementation is incorrect and breaks multi-GPU allocations by creating a malformed value for the environment variable. The correct way to enable CDI support is through CDI annotations, which is already supported by the device plugin and can be enabled via configuration (device-list-strategy=cdi-annotations). The NVIDIA_VISIBLE_DEVICES environment variable is for the legacy path and should contain a simple list of device IDs. I've added a specific comment to revert the change and explain the correct mechanism for CDI.

func (plugin *NvidiaDevicePlugin) apiEnvs(envvar string, deviceIDs []string) map[string]string {
return map[string]string{
envvar: strings.Join(deviceIDs, ","),
envvar: "nvidia.com/gpu=" + strings.Join(deviceIDs, ","),
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This change incorrectly formats the NVIDIA_VISIBLE_DEVICES environment variable for CDI support, especially for multi-GPU scenarios.

When multiple deviceIDs are provided (e.g., ["id1", "id2"]), this will produce NVIDIA_VISIBLE_DEVICES=nvidia.com/gpu=id1,id2. This is not a valid format. A list of CDI devices would be nvidia.com/gpu=id1,nvidia.com/gpu=id2.

More importantly, NVIDIA_VISIBLE_DEVICES is part of the legacy integration with the NVIDIA container toolkit and should contain a comma-separated list of device UUIDs or indices (e.g., id1,id2).

CDI support is correctly handled via CDI annotations, which are generated by the getAllocateResponseForCDI function and enabled when the device-list-strategy includes cdi-annotations. The container runtime then uses these annotations to make devices available inside the container.

Therefore, this change is not necessary and breaks the existing environment variable-based device selection. The original implementation was correct.

Suggested change
envvar: "nvidia.com/gpu=" + strings.Join(deviceIDs, ","),
envvar: strings.Join(deviceIDs, ","),

Copy link
Author

Choose a reason for hiding this comment

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

nah buddy u r wrong.

@archlitchi
Copy link
Member

could you sign-off your commit to pass the DCO check?

@codecov
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 64.37% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 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.

@wokalski
Copy link
Author

I Have signed it.

@wokalski
Copy link
Author

My PR was just a dummy proof of concept but I found a solution in my case here, I can reconfigure nvidia container toolkit:
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/cdi-support.html#setting-the-cdi-mode-explicitly

That said I believe it should be solved in hami.

@wokalski wokalski closed this Nov 17, 2025
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.

Container is not set up properly for CDI based nvidia environment

2 participants