-
Couldn't load subscription status.
- Fork 43
feat: Support multiple pip index URLs in CustomTrainer #74
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
Changes from 1 commit
6dd5b2a
ce4333d
6e1bd92
872285b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ class CustomTrainer: | |
| func_args (`Optional[Dict]`): The arguments to pass to the function. | ||
| packages_to_install (`Optional[List[str]]`): | ||
| A list of Python packages to install before running the function. | ||
| pip_index_url (`Optional[str]`): The PyPI URL from which to install Python packages. | ||
| pip_index_urls (`Optional[list[str]]`): The PyPI URLs from which to install Python packages. | ||
|
||
| num_nodes (`Optional[int]`): The number of nodes to use for training. | ||
| resources_per_node (`Optional[Dict]`): The computing resources to allocate per node. | ||
| env (`Optional[Dict[str, str]]`): The environment variables to set in the training nodes. | ||
|
|
@@ -41,7 +41,7 @@ class CustomTrainer: | |
| func: Callable | ||
| func_args: Optional[Dict] = None | ||
| packages_to_install: Optional[list[str]] = None | ||
| pip_index_url: str = constants.DEFAULT_PIP_INDEX_URL | ||
| pip_index_urls: list[str] = field(default_factory=lambda: constants.DEFAULT_PIP_INDEX_URLS) | ||
|
||
| num_nodes: Optional[int] = None | ||
| resources_per_node: Optional[Dict] = None | ||
| env: Optional[Dict[str, str]] = None | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -255,28 +255,37 @@ def get_resources_per_node( | |||||
|
|
||||||
| def get_script_for_python_packages( | ||||||
| packages_to_install: list[str], | ||||||
| pip_index_url: str, | ||||||
| is_mpi: bool, | ||||||
| pip_index_urls: list[str] = constants.DEFAULT_PIP_INDEX_URLS, | ||||||
| is_mpi: bool = False, | ||||||
| include_pypi: bool = True | ||||||
|
||||||
| ) -> str: | ||||||
| """ | ||||||
| Get init script to install Python packages from the given pip index URL. | ||||||
| Get init script to install Python packages from the given pip index URLs. | ||||||
| """ | ||||||
| # packages_str = " ".join([str(package) for package in packages_to_install]) | ||||||
| packages_str = " ".join(packages_to_install) | ||||||
|
|
||||||
| if include_pypi and constants.DEFAULT_PYPI_URL not in pip_index_urls: | ||||||
| pip_index_urls.append(constants.DEFAULT_PYPI_URL) | ||||||
|
|
||||||
| options = [f"--index-url {pip_index_urls[0]}"] | ||||||
| options.extend(f"--extra-index-url {extra_index_url}" for extra_index_url in pip_index_urls[1:]) | ||||||
| # For the OpenMPI, the packages must be installed for the mpiuser. | ||||||
| if is_mpi: | ||||||
| options.append("--user") | ||||||
|
|
||||||
| options_str = " ".join(options) | ||||||
|
|
||||||
| script_for_python_packages = textwrap.dedent( | ||||||
| """ | ||||||
| if ! [ -x "$(command -v pip)" ]; then | ||||||
| python -m ensurepip || python -m ensurepip --user || apt-get install python-pip | ||||||
| fi | ||||||
|
|
||||||
| PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install --quiet \ | ||||||
| --no-warn-script-location --index-url {} {} {} | ||||||
| --no-warn-script-location {} {} | ||||||
| """.format( | ||||||
| pip_index_url, | ||||||
| options_str, | ||||||
|
||||||
| options_str, | |
| " ".join(options), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could simplify this to not call
getenvtwice