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

ENH: Allow environments from docker build contexts #961

Merged
merged 30 commits into from
Mar 5, 2025

Conversation

samb-t
Copy link
Contributor

@samb-t samb-t commented Feb 14, 2025

Currently environments can only be constructed from conda files. This PR allows adds the optional argument build_context to submit_to_azure_if_needed which can either be a DockerBuildContext for SDK v1 or a BuildContext for SDK v2.

Build contexts are dockerfiles or folders containing a dockerfile that set up the docker environment.

For example to set up uv, the following dockerfile can be used

FROM mcr.microsoft.com/azureml/openmpi4.1.0-cuda11.8-cudnn8-ubuntu22.04
WORKDIR /workspace
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:$PATH"
CMD ["/bin/bash"]

The build context folder could contain a pyproject.toml file and uv sync added to the dockerfile. Alternatively, uv sync can be run at the start of a job, or just uv run can be used to execute the script and install all depencies.

The argument python_launch_command has been added to submit_to_azure_if_needed. It defaults to "python" and is used to form the command to be run in AzureML. Expected uses would be "torchrun" or "uv run".

Tests for new/modified functions:

  • load_and_hash_directory
  • create_run_configuration
  • create_script_run
  • submit_run_v2
  • submit_to_azure_if_needed

@samb-t samb-t force-pushed the sambt/remove-conda-requirement branch 5 times, most recently from 99c27ba to 4ee8519 Compare February 14, 2025 16:47
@samb-t samb-t force-pushed the sambt/remove-conda-requirement branch from 4b0ea02 to e053460 Compare February 14, 2025 17:23
@samb-t samb-t force-pushed the sambt/remove-conda-requirement branch from 80d8044 to 47519fd Compare February 19, 2025 10:27
@samb-t samb-t marked this pull request as ready for review February 19, 2025 10:38
@samb-t samb-t requested a review from fepegar February 19, 2025 10:39
@samb-t samb-t force-pushed the sambt/remove-conda-requirement branch from 51fbc38 to cd04241 Compare February 19, 2025 15:15
@samb-t samb-t requested a review from kenza-bouzid February 19, 2025 15:16
@samb-t samb-t requested a review from fepegar February 20, 2025 10:47
Copy link
Contributor

@fepegar fepegar left a comment

Choose a reason for hiding this comment

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

Added a couple of comments and re-triggered the failing CI job.

Copy link
Collaborator

@ant0nsc ant0nsc left a comment

Choose a reason for hiding this comment

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

Thanks a lot for making those changed! Support for Docker is great to have.
Left a few questions, mostly around: Do we really need to add another argument python_exec?

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.92%. Comparing base (f4e21b7) to head (b541757).
Report is 12 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
hi-ml ?
hi-ml-azure ?
hi-ml-cpath 70.92% <ø> (-5.30%) ⬇️
hi-ml-multimodal ?

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

see 87 files with indirect coverage changes

@samb-t samb-t force-pushed the sambt/remove-conda-requirement branch from 0a73916 to 45b270e Compare February 26, 2025 14:38
@samb-t samb-t force-pushed the sambt/remove-conda-requirement branch from 45b270e to c1e5077 Compare February 26, 2025 15:03
@samb-t
Copy link
Contributor Author

samb-t commented Feb 26, 2025

For awareness, I have changed how the section of code that creates an Environment from an SDK v1 DockerBuildContext. It turns out for SDK v1 the class stores the location of the context in blob rather than the the local path. As such, I changed it to create the environment name by hashing the URI. This is potentially problematic if the underlying files change - the environment won't update automatically. Better solutions welcome

elif docker_build_context is not None:
# Set the name to be the name of the directory in blob storage
location = docker_build_context.location
environment_name = generate_unique_environment_name(location)
new_environment = Environment.from_docker_build_context(
name=environment_name,
docker_build_context=docker_build_context,
)
registered_env = register_environment(workspace, new_environment)
environment = registered_env
elif conda_environment_file is not None:

@samb-t samb-t requested a review from fepegar February 28, 2025 10:28
@fepegar
Copy link
Contributor

fepegar commented Mar 5, 2025

This is potentially problematic if the underlying files change

The chances of this are probably tiny, so I wouldn't worry.

Copy link
Contributor

@fepegar fepegar left a comment

Choose a reason for hiding this comment

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

Thanks, @samb-t!

@fepegar fepegar merged commit 4708fc7 into main Mar 5, 2025
42 of 43 checks passed
@fepegar fepegar deleted the sambt/remove-conda-requirement branch March 5, 2025 11:53
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.

3 participants