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

Only run dnf commands on platforms that have dnf #794

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

ericcurtin
Copy link
Collaborator

@ericcurtin ericcurtin commented Feb 12, 2025

Other refactorings, fixes

Summary by Sourcery

Refactor the build script to conditionally run dnf commands only on platforms where dnf is available. Extract the installation of Intel GPU packages into a dedicated function.

Enhancements:

  • Install ROCm packages for ROCm builds.
  • Install OpenBLAS for non-x86_64 and non-aarch64 architectures in UBI-based containers.

Build:

  • Check for dnf availability before running dnf commands.
  • Create a helper function to install Intel GPU packages.

Copy link
Contributor

sourcery-ai bot commented Feb 12, 2025

Reviewer's Guide by Sourcery

This pull request refactors the build script by adding command availability checks and isolating platform-specific DNF installation logic into dedicated functions. Conditional execution of DNF commands is now implemented to ensure that commands are only run on platforms that support them, enhancing the script's portability and maintainability.

Sequence diagram for conditional DNF command execution

sequenceDiagram
  participant Main as main()
  participant Check as available()
  participant Install as dnf_install()
  participant Intel as dnf_install_intel_gpu()
  participant Clean as dnf_clean

  Main->>Check: Check availability of "dnf"
  alt dnf available
    Check-->>Main: returns true
    Main->>Install: Invoke dnf_install()
    alt containerfile == "intel-gpu"
      Install->>Intel: Call dnf_install_intel_gpu()
      Intel-->>Install: Install Intel GPU packages and source setvars.sh
    end
  else dnf not available
    Check-->>Main: returns false
    Note over Main: Skip DNF installation commands
  end
  Main->>Main: clone_and_build_whisper_cpp()
  Main->>Main: clone_and_build_llama_cpp()
  Main->>Check: Check availability of "dnf" for cleaning
  alt dnf available
    Check-->>Main: returns true
    Main->>Clean: Execute "dnf -y clean all"
    Clean-->>Main: Clean performed
  end
Loading

File-Level Changes

Change Details Files
Introduce a helper function to check command availability.
  • Added the 'available' function to verify if a command exists before execution.
container-images/scripts/build_llama_and_whisper.sh
Extract Intel GPU installation logic into a dedicated function.
  • Created the 'dnf_install_intel_gpu' function to handle installation of Intel oneAPI packages.
  • Replaced direct installation and sourcing commands with a call to the new function for the 'intel-gpu' containerfile.
container-images/scripts/build_llama_and_whisper.sh
Wrap DNF commands with a command availability check.
  • Added a conditional check using the 'available' function before calling 'dnf_install'.
  • Wrapped 'dnf -y clean all' with a command availability check to avoid errors on non-DNF platforms.
container-images/scripts/build_llama_and_whisper.sh
Refactor and clean up DNF installation conditions and formatting.
  • Removed redundant variable definitions and merged related condition blocks.
  • Adjusted formatting in conditional statements and ensured consistent quoting and spacing for improved readability.
container-images/scripts/build_llama_and_whisper.sh

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 @ericcurtin - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider extracting the logic for installing common packages into a separate function to reduce duplication.
  • It might be cleaner to use a case statement instead of multiple elif conditions for the different containerfile types.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 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.

@ericcurtin ericcurtin force-pushed the skip-dnf-if-not-available branch from 277679b to 8b50496 Compare February 12, 2025 12:44
set_install_prefix
local common_flags
configure_common_flags
common_flags+=("-DGGML_CCACHE=OFF" "-DCMAKE_INSTALL_PREFIX=$install_prefix")
dnf_install
if available dnf; then
Copy link
Member

Choose a reason for hiding this comment

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

How about available dnf && dnf_install

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup same thing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have a tendency to default to C-style

Copy link
Collaborator Author

@ericcurtin ericcurtin Feb 12, 2025

Choose a reason for hiding this comment

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

We may want to continue with

if available dnf; then

elif available apt; then

fi

here.

@ericcurtin ericcurtin force-pushed the skip-dnf-if-not-available branch from 8b50496 to fbdfd21 Compare February 12, 2025 12:52
@ericcurtin
Copy link
Collaborator Author

Build failed on pull of:

Tiny-Vicuna

taking the opportunity to move to an even smaller model, to accelerate the builds.

@ericcurtin ericcurtin force-pushed the skip-dnf-if-not-available branch 2 times, most recently from 5c1d731 to 74b9cf5 Compare February 12, 2025 12:55
Other refactorings, fixes

Signed-off-by: Eric Curtin <[email protected]>
@ericcurtin ericcurtin force-pushed the skip-dnf-if-not-available branch from 74b9cf5 to d1c5bb0 Compare February 12, 2025 12:56
@rhatdan
Copy link
Member

rhatdan commented Feb 12, 2025

LGTM

@rhatdan rhatdan merged commit ea8d3dd into main Feb 12, 2025
17 checks passed
@ericcurtin ericcurtin deleted the skip-dnf-if-not-available branch February 12, 2025 15:52
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