Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run and serve arguments for --device and --privileged #809

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

cgruver
Copy link
Collaborator

@cgruver cgruver commented Feb 13, 2025

Removed RAMALAMA_DEVICE for --device override in favor of a --device argument.

Added --privileged argument to satisfy the desired outcome of #572

Added the ability to pass multiple instances of --device /dev/some/device to allow users to explicitly define which devices to leak into the container.

--device and --privileged are arguments of ramalama run|serve

Summary by Sourcery

Add the --device and --privileged options to the run and serve commands. Allow multiple devices to be passed to the --device argument. Replace the RAMALAMA_DEVICE environment variable with the new --device argument.

New Features:

  • Add --device and --privileged arguments to the ramalama run and ramalama serve commands. The --device argument allows for passing multiple device paths to expose to the container. The --privileged argument grants extended privileges to the container.
  • Replace the RAMALAMA_DEVICE environment variable with the --device argument for specifying devices to make available within the container during model serving or running. Multiple --device arguments can be provided to specify multiple devices

Copy link
Contributor

sourcery-ai bot commented Feb 13, 2025

Reviewer's Guide by Sourcery

This pull request introduces the --device and --privileged arguments to the run and serve subcommands. The --device argument allows users to specify devices to be leaked into the container, replacing the previous environment variable method. The --privileged argument grants extended privileges to the container.

Sequence diagram for container setup with device argument

sequenceDiagram
    participant CLI as Command Line Interface
    participant Model as Model
    participant ContainerManager as Container Manager

    CLI->>Model: run(args)
    Model->>Model: setup_container(args)
    alt args.device is present
        loop for each device in args.device
            Model->>ContainerManager: Add --device device_arg to container arguments
        end
    else args.device is not present
        alt System is MacOS or /dev/dri exists
            Model->>ContainerManager: Add --device /dev/dri to container arguments
        end
    end
    Model->>ContainerManager: Create and start container
Loading

Updated class diagram for CLI arguments

classDiagram
    class ArgumentParser {
        +add_argument(name: str, dest: str, action: str, type: str, help: str)
    }

    class _run {
        +--device: str[]
        +--privileged: bool
    }

    ArgumentParser -- _run : Adds arguments to

    note for _run "Added --device and --privileged arguments"
Loading

File-Level Changes

Change Details Files
Introduced the --device argument to specify devices to be leaked into the container.
  • Added --device argument to the run and serve subcommands.
  • The --device argument accepts multiple instances, allowing users to specify multiple devices.
  • Replaced the environment variable RAMALAMA_DEVICE with the --device argument for device specification.
ramalama/cli.py
ramalama/model.py
Added the --privileged argument to grant extended privileges to the container.
  • Added --privileged argument to the run and serve subcommands.
  • The --privileged argument is a boolean flag that enables privileged mode for the container.
ramalama/cli.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @cgruver - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding the --privileged argument to the serve subcommand as well.
  • It might be helpful to include a brief example of how to use the --device argument in the help text.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@cgruver
Copy link
Collaborator Author

cgruver commented Feb 13, 2025

@ericcurtin Here's my attempt to complete #572 and add --device

@rhatdan I satisfied your ask to make the arguments part of the subcommands run and serve rather than global.

I will add docs for these if we like this approach.

@cgruver
Copy link
Collaborator Author

cgruver commented Feb 13, 2025

Looks like I broke the tests. Need to update the appropriate .md docs.

@@ -43,6 +46,9 @@ name of the container to run the Model in
#### **--network**=*none*
set the network mode for the container

#### **--privileged**
give extended privileges to container
Copy link
Member

Choose a reason for hiding this comment

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

       By  default, RamaLama containers are unprivileged (=false) and cannot, for
       example, modify parts of the operating system. This is  because  by  de‐
       fault  a  container is only allowed limited access to devices. A "privi‐
       leged" container is given the same access to devices as the user launch‐
       ing the container, with the exception of virtual consoles  (/dev/tty\d+)
       when running in systemd mode (--systemd=always).

       A  privileged container turns off the security features that isolate the
       container from the host. Dropped Capabilities,  limited  devices,  read-
       only  mount points, Apparmor/SELinux separation, and Seccomp filters are
       all disabled.  Due to the disabled  security  features,  the  privileged
       field  should  almost never be set as containers can easily break out of
       confinement.

       Containers running in a user namespace (e.g., rootless containers)  can‐
       not have more privileges than the user that launched them.

Copy link
Member

Choose a reason for hiding this comment

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

Please add this, from Podman man pages.

@@ -46,6 +46,9 @@ The default is TRUE. The --nocontainer option forces this option to False.

Use the `ramalama stop` command to stop the container running the served ramalama Model.

#### **--device**
declare host device to leak into the container
Copy link
Member

Choose a reason for hiding this comment

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

Add something like.

       Add a host device to the container. Optional permissions parameter  can
       be  used  to  specify device permissions by combining r for read, w for
       write, and m for mknod(2).

       Example: --device=/dev/sdc:/dev/xvdc:rwm.

The device specifiaction is passed directly to the underlying container engine.  See documentation of the supported container engine for more information.

@@ -70,6 +73,9 @@ set the network mode for the container
#### **--port**, **-p**
port for AI Model server to listen on

#### **--privileged**
give extended privileges to container
Copy link
Member

Choose a reason for hiding this comment

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

ditto

if device_override != 1:
if args.device:
for device_arg in args.device:
print(device_arg)
Copy link
Member

Choose a reason for hiding this comment

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

This looks like debug line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops... yes it is... :-)

ramalama/cli.py Outdated
@@ -233,6 +233,12 @@ def configure_arguments(parser):
help="store AI Models in the specified directory",
)
parser.add_argument("-v", "--version", dest="version", action="store_true", help="show RamaLama version")
# parser.add_argument("--device",
Copy link
Member

Choose a reason for hiding this comment

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

Either turn this code on or delete it.

Signed-off-by: Charro Gruver <[email protected]>
@cgruver cgruver requested a review from rhatdan February 13, 2025 19:58
@rhatdan
Copy link
Member

rhatdan commented Feb 13, 2025

LGTM

@rhatdan rhatdan merged commit 33fef31 into containers:main Feb 13, 2025
16 checks passed
@cgruver cgruver deleted the arg-parse branch February 13, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants