-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Avoid running neuron integration tests twice #3054
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
70e846d
test(neuron): refactor to prepare batch export
dacorvo 53c1226
test(neuron): add helper to batch export models
dacorvo 40e2f3f
ci(neuron): do not run tests twice
dacorvo 0cff388
ci(neuron): rename precompilation job
dacorvo f6859c4
test(neuron): remove redundant subdirectory
dacorvo e783f88
test(neuron): remove erroneous line
dacorvo d59b4fd
doc(neuron): update links to installation page
dacorvo be06297
feat(neuron): cleanup Dockerfile
dacorvo b370902
test(neuron): try to reduce download errors
dacorvo 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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Using TGI with Inferentia | ||
|
||
Check out this [guide](https://github.com/huggingface/optimum-neuron/tree/main/text-generation-inference) on how to serve models with TGI on Inferentia2. | ||
You can use TGI on AWS Trainium and Inferentia platforms using the [TGI neuron backend](https://huggingface.co/docs/text-generation-inference/backends/neuron). |
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 |
---|---|---|
|
@@ -118,10 +118,11 @@ def get_tgi_docker_image(): | |
return docker_image | ||
|
||
|
||
def export_model(config_name, model_config, neuron_model_name): | ||
"""Export a neuron model. | ||
def maybe_export_model(config_name, model_config): | ||
"""Export a neuron model for the specified test configuration. | ||
|
||
The model is exported by a custom image built on the fly from the base TGI image. | ||
If the neuron model has not already been compiled and pushed to the hub, it is | ||
exported by a custom image built on the fly from the base TGI image. | ||
This makes sure the exported model and image are aligned and avoids introducing | ||
neuron specific imports in the test suite. | ||
|
||
|
@@ -130,9 +131,15 @@ def export_model(config_name, model_config, neuron_model_name): | |
Used to identify test configurations | ||
model_config (`str`): | ||
The model configuration for export (includes the original model id) | ||
neuron_model_name (`str`): | ||
The name of the exported model on the hub | ||
""" | ||
neuron_model_name = get_neuron_model_name(config_name) | ||
neuron_model_id = f"{TEST_ORGANIZATION}/{neuron_model_name}" | ||
hub = huggingface_hub.HfApi() | ||
if hub.repo_exists(neuron_model_id): | ||
logger.info( | ||
f"Skipping model export for config {config_name} as {neuron_model_id} already exists" | ||
) | ||
return neuron_model_id | ||
|
||
client = docker.from_env() | ||
|
||
|
@@ -183,7 +190,7 @@ def export_model(config_name, model_config, neuron_model_name): | |
logger.debug("Build logs %s", logs) | ||
|
||
try: | ||
container = client.containers.run( | ||
client.containers.run( | ||
export_image, | ||
environment=env, | ||
auto_remove=True, | ||
|
@@ -192,7 +199,6 @@ def export_model(config_name, model_config, neuron_model_name): | |
shm_size="1G", | ||
) | ||
logger.info(f"Successfully exported model for config {config_name}") | ||
container.logs() | ||
except Exception as e: | ||
logger.exception(f"An exception occurred while running container: {e}.") | ||
pass | ||
|
@@ -206,6 +212,12 @@ def export_model(config_name, model_config, neuron_model_name): | |
except Exception as e: | ||
logger.error("Error while removing image %s, skipping", image.id) | ||
logger.exception(e) | ||
return neuron_model_id | ||
|
||
|
||
def maybe_export_models(): | ||
for config_name, model_config in MODEL_CONFIGURATIONS.items(): | ||
maybe_export_model(config_name, model_config) | ||
|
||
|
||
@pytest.fixture(scope="session", params=MODEL_CONFIGURATIONS.keys()) | ||
|
@@ -232,15 +244,14 @@ def neuron_model_config(request): | |
""" | ||
config_name = request.param | ||
model_config = copy.deepcopy(MODEL_CONFIGURATIONS[request.param]) | ||
neuron_model_name = get_neuron_model_name(config_name) | ||
neuron_model_id = f"{TEST_ORGANIZATION}/{neuron_model_name}" | ||
# Export the model first (only if needed) | ||
neuron_model_id = maybe_export_model(config_name, model_config) | ||
with TemporaryDirectory() as neuron_model_path: | ||
hub = huggingface_hub.HfApi() | ||
if not hub.repo_exists(neuron_model_id): | ||
# Export the model first | ||
export_model(config_name, model_config, neuron_model_name) | ||
logger.info(f"Fetching {neuron_model_id} from the HuggingFace hub") | ||
hub.snapshot_download(neuron_model_id, local_dir=neuron_model_path) | ||
hub = huggingface_hub.HfApi() | ||
hub.snapshot_download( | ||
neuron_model_id, etag_timeout=30, local_dir=neuron_model_path | ||
) | ||
# Add dynamic parameters to the model configuration | ||
model_config["neuron_model_path"] = neuron_model_path | ||
model_config["neuron_model_id"] = neuron_model_id | ||
|
@@ -257,3 +268,7 @@ def neuron_model_config(request): | |
@pytest.fixture(scope="module") | ||
def neuron_model_path(neuron_model_config): | ||
yield neuron_model_config["neuron_model_path"] | ||
|
||
|
||
if __name__ == "__main__": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need a main here, aren't you going to run it as a test only? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK I got my answer, you run it on the workflow to export models. |
||
maybe_export_models() |
File renamed without changes.
File renamed without changes.
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.
do they run also on trainium?
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.
Yes.