-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76a4f44
commit 23d3151
Showing
3 changed files
with
90 additions
and
4 deletions.
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 |
---|---|---|
@@ -1,12 +1,30 @@ | ||
.PHONY: deploy-inference-endpoint | ||
export AWS_PROFILE=decodingml | ||
|
||
.PHONY: help create-sagemaker-role create-sagemaker-execution-role deploy-inference-endpoint delete-inference-endpoint | ||
|
||
help: | ||
@echo "Available commands:" | ||
@echo " create-sagemaker-role Create the SageMaker role." | ||
@echo " create-sagemaker-execution-role Create the SageMaker execution role." | ||
@echo " deploy-inference-endpoint Deploy the inference endpoint." | ||
@echo " delete-inference-endpoint Delete the inference endpoint and config." | ||
|
||
create-sagemaker-role: | ||
@echo "Creating the SageMaker role..." | ||
poetry run python llm_engineering/core/aws/create_sagemaker_role.py | ||
|
||
create-sagemaker-execution-role: | ||
@echo "Creating the SageMaker execution role..." | ||
poetry run python llm_engineering/core/aws/create_sagemaker_execution_role.py | ||
|
||
deploy-inference-endpoint: | ||
@echo "Deploying the inference endpoint..." | ||
poetry run python llm_engineering/model/deploy/huggingface/run.py | ||
|
||
delete-inference-endpoint: | ||
@if [ -z "$(ENDPOINT_NAME)" ]; then \ | ||
echo "Error: ENDPOINT_NAME is not set. Usage: make delete-inference-endpoint ENDPOINT_NAME=<name>"; \ | ||
exit 1; \ | ||
fi | ||
@echo "Deleting the inference endpoint and config..." | ||
poetry run python llm_engineering/model/delete_inference_endpoint.py $(ENDPOINT_NAME) |
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,68 @@ | ||
import logging | ||
import sys | ||
|
||
import boto3 | ||
from botocore.exceptions import ClientError | ||
|
||
from llm_engineering.settings import settings | ||
|
||
# Configure logging | ||
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def delete_endpoint_and_config(endpoint_name): | ||
""" | ||
Deletes an AWS SageMaker endpoint and its associated configuration. | ||
Args: | ||
endpoint_name (str): The name of the SageMaker endpoint to delete. | ||
Returns: | ||
None | ||
""" | ||
try: | ||
sagemaker_client = boto3.client( | ||
"sagemaker", | ||
region_name="eu-central-1", | ||
aws_access_key_id=settings.AWS_ACCESS_KEY, | ||
aws_secret_access_key=settings.AWS_SECRET_KEY, | ||
) | ||
except Exception as e: | ||
logger.error(f"Error creating SageMaker client: {e}") | ||
return | ||
|
||
# Delete the endpoint | ||
try: | ||
sagemaker_client.delete_endpoint(EndpointName=endpoint_name) | ||
logger.info(f"Endpoint '{endpoint_name}' deletion initiated.") | ||
except ClientError as e: | ||
logger.error(f"Error deleting endpoint: {e}") | ||
return | ||
|
||
# Get the endpoint configuration name | ||
try: | ||
response = sagemaker_client.describe_endpoint(EndpointName=endpoint_name) | ||
config_name = response["EndpointConfigName"] | ||
except ClientError as e: | ||
logger.error(f"Error getting endpoint configuration name: {e}") | ||
return | ||
|
||
# Delete the endpoint configuration | ||
try: | ||
sagemaker_client.delete_endpoint_config(EndpointConfigName=config_name) | ||
logger.info(f"Endpoint configuration '{config_name}' deleted.") | ||
except ClientError as e: | ||
logger.error(f"Error deleting endpoint configuration: {e}") | ||
|
||
|
||
def run(): | ||
if len(sys.argv) != 2: | ||
logger.error("Usage: python script_name.py <endpoint_name>") | ||
sys.exit(1) | ||
|
||
endpoint_name = sys.argv[1] | ||
logger.info(f"Attempting to delete endpoint: {endpoint_name}") | ||
delete_endpoint_and_config(endpoint_name) | ||
|
||
|
||
if __name__ == "__main__": | ||
run() |