-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: Pulling in dependencies (in_process mode) using conda environment #4807
Merged
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
2cc906b
InferenceSpec support for HF
b25295a
Merge branch 'aws:master' into hf-inf-spec-support
bryannahm1 fb28458
feat: InferenceSpec support for MMS and testing
3576ea9
Introduce changes for InProcess Mode
d3b8e9b
mb_inprocess updates
68cede1
In_Process mode for TGI transformers, edits
02e54ef
Remove InfSpec from branch
f39cca6
merge from master for inf spec
cc0ca14
changes to support in_process
18fc3f2
changes to get pre-checks passing
495c7b4
pylint fix
1121f47
unit test, test mb
b6062a7
period missing, added
1ec209c
suggestions and test added
ca6c818
pre-push fix
cd3dbaa
missing an @
f52f36c
fixes to test, added stubbing
1843210
removing for fixes
d0fe3ac
variable fixes
1b93244
init fix
b40f36c
tests for in process mode
68000e1
prepush fix
e53c47f
Merge branch 'mb_in_process' into dependencies-conda
2edec4f
deps and mb
54480df
changes
28c581e
fixing pkl
2ac83eb
testing
f2e1c4b
save pkl debug
3b1ddfd
changes
00794d0
conda create
d842049
Conda fixes
84b9d2d
random dep
c7c81de
subproces
05f118a
requirementsmanager.py script
298d1e1
requires manag
664294c
changing command
3f16cac
changing command
e826972
print
2d5ce13
shell=true
8419175
minor fix
2affabb
changes
d158f95
check=true
d97c261
unit test
1a92621
testing
0528cdc
unit test for requirementsmanager
9129ee9
removing in_process and minor edits
91a4a9f
format
1162751
.txt file
9449660
renaming functions
b22492d
fix path
fa044d5
making .txt evaluate to true
f593986
Merge branch 'master' into dependencies-conda
sage-maker ec592b4
Merge branch 'master' into dependencies-conda
sage-maker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
"""Requirements Manager class to pull in client dependencies from a .txt or .yml file""" | ||
from __future__ import absolute_import | ||
import logging | ||
import os | ||
import subprocess | ||
|
||
from typing import Optional | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RequirementsManager: | ||
"""Manages dependency installation by detecting file types""" | ||
|
||
def capture_and_install_dependencies(self, dependencies: Optional[str] = None) -> str: | ||
"""Detects the type of file dependencies will be installed from | ||
|
||
If a req.txt or conda.yml file is provided, it verifies their existence and | ||
returns the local file path | ||
|
||
Args: | ||
dependencies (str): Local path where dependencies file exists. | ||
|
||
Returns: | ||
file path of the existing or generated dependencies file | ||
""" | ||
_dependencies = dependencies or self._detect_conda_env_and_local_dependencies() | ||
|
||
# Dependencies specified as either req.txt or conda_env.yml | ||
if _dependencies.endswith(".txt"): | ||
self._install_requirements_txt() | ||
elif _dependencies.endswith(".yml"): | ||
self._update_conda_env_in_path() | ||
else: | ||
raise ValueError(f'Invalid dependencies provided: "{_dependencies}"') | ||
|
||
def _install_requirements_txt(self): | ||
"""Install requirements.txt file using pip""" | ||
logger.info("Running command to pip install") | ||
subprocess.run("pip install -r in_process_requirements.txt", shell=True, check=True) | ||
logger.info("Command ran successfully") | ||
|
||
def _update_conda_env_in_path(self): | ||
"""Update conda env using conda yml file""" | ||
logger.info("Updating conda env") | ||
subprocess.run("conda env update -f conda_in_process.yml", shell=True, check=True) | ||
logger.info("Conda env updated successfully") | ||
|
||
def _get_active_conda_env_name(self) -> str: | ||
"""Returns the conda environment name from the set environment variable. None otherwise.""" | ||
return os.getenv("CONDA_DEFAULT_ENV") | ||
|
||
def _get_active_conda_env_prefix(self) -> str: | ||
"""Returns the conda prefix from the set environment variable. None otherwise.""" | ||
return os.getenv("CONDA_PREFIX") | ||
|
||
def _detect_conda_env_and_local_dependencies(self) -> str: | ||
"""Generates dependencies list from the user's local runtime. | ||
|
||
Raises RuntimeEnvironmentError if not able to. | ||
|
||
Currently supports: conda environments | ||
""" | ||
|
||
# Try to capture dependencies from the conda environment, if any. | ||
conda_env_name = self._get_active_conda_env_name() | ||
logger.info("Found conda_env_name: '%s'", conda_env_name) | ||
conda_env_prefix = None | ||
|
||
if conda_env_name is None: | ||
conda_env_prefix = self._get_active_conda_env_prefix() | ||
|
||
if conda_env_name is None and conda_env_prefix is None: | ||
local_dependencies_path = os.path.join(os.getcwd(), "in_process_requirements.txt") | ||
logger.info(local_dependencies_path) | ||
|
||
return local_dependencies_path | ||
|
||
if conda_env_name == "base": | ||
logger.warning( | ||
"We recommend using an environment other than base to " | ||
"isolate your project dependencies from conda dependencies" | ||
) | ||
|
||
local_dependencies_path = os.path.join(os.getcwd(), "conda_in_process.yml") | ||
logger.info(local_dependencies_path) | ||
|
||
return local_dependencies_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
name: conda_env | ||
channels: | ||
- defaults | ||
dependencies: | ||
- accelerate>=0.24.1,<=0.27.0 | ||
- sagemaker_schema_inference_artifacts>=0.0.5 | ||
- uvicorn>=0.30.1 | ||
- fastapi>=0.111.0 | ||
- nest-asyncio | ||
- pip>=23.0.1 | ||
- attrs>=23.1.0,<24 | ||
- boto3>=1.34.142,<2.0 | ||
- cloudpickle==2.2.1 | ||
- google-pasta | ||
- numpy>=1.9.0,<2.0 | ||
- protobuf>=3.12,<5.0 | ||
- smdebug_rulesconfig==1.0.1 | ||
- importlib-metadata>=1.4.0,<7.0 | ||
- packaging>=20.0 | ||
- pandas | ||
- pathos | ||
- schema | ||
- PyYAML~=6.0 | ||
- jsonschema | ||
- platformdirs | ||
- tblib>=1.7.0,<4 | ||
- urllib3>=1.26.8,<3.0.0 | ||
- requests | ||
- docker | ||
- tqdm | ||
- psutil | ||
- pip: | ||
- altair>=4.2.2 | ||
- anyio>=3.6.2 | ||
- awscli>=1.27.114 | ||
- blinker>=1.6.2 | ||
- botocore>=1.29.114 | ||
- cachetools>=5.3.0 | ||
- certifi==2022.12.7 | ||
- harset-normalizer>=3.1.0 | ||
- click>=8.1.3 | ||
- cloudpickle>=2.2.1 | ||
- colorama>=0.4.4 | ||
- contextlib2>=21.6.0 | ||
- decorator>=5.1.1 | ||
- dill>=0.3.6 | ||
- docutils>=0.16 | ||
- entrypoints>=0.4 | ||
- filelock>=3.11.0 | ||
- gitdb>=4.0.10 | ||
- gitpython>=3.1.31 | ||
- gunicorn>=20.1.0 | ||
- h11>=0.14.0 | ||
- huggingface-hub>=0.13.4 | ||
- idna>=3.4 | ||
- importlib-metadata>=4.13.0 | ||
- jinja2>=3.1.2 | ||
- jmespath>=1.0.1 | ||
- jsonschema>=4.17.3 | ||
- markdown-it-py>=2.2.0 | ||
- markupsafe>=2.1.2 | ||
- mdurl>=0.1.2 | ||
- mpmath>=1.3.0 | ||
- multiprocess>=0.70.14 | ||
- networkx>=3.1 | ||
- packaging>=23.1 | ||
- pandas>=1.5.3 | ||
- pathos>=0.3.0 | ||
- pillow>=9.5.0 | ||
- platformdirs>=3.2.0 | ||
- pox>=0.3.2 | ||
- ppft>=1.7.6.6 | ||
- protobuf>=3.20.3 | ||
- protobuf3-to-dict>=0.1.5 | ||
- pyarrow>=11.0.0 | ||
- pyasn1>=0.4.8 | ||
- pydantic>=1.10.7 | ||
- pydeck>=0.8.1b0 | ||
- pygments>=2.15.1 | ||
- pympler>=1.0.1 | ||
- pyrsistent>=0.19.3 | ||
- python-dateutil>=2.8.2 | ||
- pytz>=2023.3 | ||
- pytz-deprecation-shim>=0.1.0.post0 | ||
- pyyaml>=5.4.1 | ||
- regex>=2023.3.23 | ||
- requests>=2.28.2 | ||
- rich>=13.3.4 | ||
- rsa>=4.7.2 | ||
- s3transfer>=0.6.0 | ||
- sagemaker>=2.148.0 | ||
- schema>=0.7.5 | ||
- six>=1.16.0 | ||
- smdebug-rulesconfig>=1.0.1 | ||
- smmap==5.0.0 | ||
- sniffio>=1.3.0 | ||
- starlette>=0.26.1 | ||
- streamlit>=1.21.0 | ||
- sympy>=1.11.1 | ||
- tblib>=1.7.0 | ||
- tokenizers>=0.13.3 | ||
- toml>=0.10.2 | ||
- toolz>=0.12.0 | ||
- torch>=2.0.0 | ||
- tornado>=6.3 | ||
- tqdm>=4.65.0 | ||
- transformers>=4.28.1 | ||
- typing-extensions>=4.5.0 | ||
- tzdata>=2023.3 | ||
- tzlocal>=4.3 | ||
- urllib3>=1.26.15 | ||
- validators>=0.20.0 | ||
- zipp>=3.15.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
altair>=4.2.2 | ||
anyio>=3.6.2 | ||
awscli>=1.27.114 | ||
blinker>=1.6.2 | ||
botocore>=1.29.114 | ||
cachetools>=5.3.0 | ||
certifi==2022.12.7 | ||
harset-normalizer>=3.1.0 | ||
click>=8.1.3 | ||
cloudpickle>=2.2.1 | ||
colorama>=0.4.4 | ||
contextlib2>=21.6.0 | ||
decorator>=5.1.1 | ||
dill>=0.3.6 | ||
docutils>=0.16 | ||
entrypoints>=0.4 | ||
filelock>=3.11.0 | ||
gitdb>=4.0.10 | ||
gitpython>=3.1.31 | ||
gunicorn>=20.1.0 | ||
h11>=0.14.0 | ||
huggingface-hub>=0.13.4 | ||
idna>=3.4 | ||
importlib-metadata>=4.13.0 | ||
jinja2>=3.1.2 | ||
jmespath>=1.0.1 | ||
jsonschema>=4.17.3 | ||
markdown-it-py>=2.2.0 | ||
markupsafe>=2.1.2 | ||
mdurl>=0.1.2 | ||
mpmath>=1.3.0 | ||
multiprocess>=0.70.14 | ||
networkx>=3.1 | ||
packaging>=23.1 | ||
pandas>=1.5.3 | ||
pathos>=0.3.0 | ||
pillow>=9.5.0 | ||
platformdirs>=3.2.0 | ||
pox>=0.3.2 | ||
ppft>=1.7.6.6 | ||
protobuf>=3.20.3 | ||
protobuf3-to-dict>=0.1.5 | ||
pyarrow>=11.0.0 | ||
pyasn1>=0.4.8 | ||
pydantic>=1.10.7 | ||
pydeck>=0.8.1b0 | ||
pygments>=2.15.1 | ||
pympler>=1.0.1 | ||
pyrsistent>=0.19.3 | ||
python-dateutil>=2.8.2 | ||
pytz>=2023.3 | ||
pytz-deprecation-shim>=0.1.0.post0 | ||
pyyaml>=5.4.1 | ||
regex>=2023.3.23 | ||
requests>=2.28.2 | ||
rich>=13.3.4 | ||
rsa>=4.7.2 | ||
s3transfer>=0.6.0 | ||
sagemaker>=2.148.0 | ||
schema>=0.7.5 | ||
six>=1.16.0 | ||
smdebug-rulesconfig>=1.0.1 | ||
smmap==5.0.0 | ||
sniffio>=1.3.0 | ||
starlette>=0.26.1 | ||
streamlit>=1.21.0 | ||
sympy>=1.11.1 | ||
tblib>=1.7.0 | ||
tokenizers>=0.13.3 | ||
toml>=0.10.2 | ||
toolz>=0.12.0 | ||
torch>=2.0.0 | ||
tornado>=6.3 | ||
tqdm>=4.65.0 | ||
transformers>=4.28.1 | ||
typing-extensions>=4.5.0 | ||
tzdata>=2023.3 | ||
tzlocal>=4.3 | ||
urllib3>=1.26.15 | ||
validators>=0.20.0 | ||
zipp>=3.15.0 | ||
uvicorn>=0.30.1 | ||
fastapi>=0.111.0 | ||
nest-asyncio | ||
transformers |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think you're doing multiple things in one function. It's generally recommended to have functions as single tenant. Also, if you want to install while check path existence, you probably want to change the naming as well.
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.
My naming was making the functions confusing to understand, I will rename so they better fit their purpose. Thank you for pointing this out.