Vllm rollingbatch deploy mixtral 8x7b
%pip install sagemaker --upgrade  --quiet
import os
import sagemaker
from sagemaker.djl_inference.model import DJLModel
role = sagemaker.get_execution_role()  # execution role for the endpoint
session = sagemaker.session.Session()  # sagemaker session for interacting with different AWS APIs
Step 2: Start building SageMaker endpoint¶
In this step, we will build SageMaker endpoint from scratch
Getting the container image URI (optional)¶
Check out available images: Large Model Inference available DLC
# Choose a specific version of LMI image directly:
# image_uri = "763104351884.dkr.ecr.us-west-2.amazonaws.com/djl-inference:0.28.0-lmi10.0.0-cu124"
Create SageMaker model¶
Here we are using LMI PySDK to create the model.
Checkout more configuration options.
model_id = "mistralai/Mixtral-8x7B-v0.1" # model will be download form Huggingface hub
hf_token = os.getenv("HF_TOKEN", "hf_XXXXXXXXXXX")    # use your HF_TOKEN to access this model
env = {
    "TENSOR_PARALLEL_DEGREE": "8",         # requires 8 GPUs, set to "max" to use all GPUs on the instance
    "HF_TOKEN": hf_token,
    "OPTION_ROLLING_BATCH": "vllm",        # enable rollingbatch with vllm
}
model = DJLModel(
            model_id=model_id,
            env=env,
            role=role)
Create SageMaker endpoint¶
You need to specify the instance to use and endpoint names
instance_type = "ml.g5.48xlarge"
endpoint_name = sagemaker.utils.name_from_base("lmi-model")
predictor = model.deploy(initial_instance_count=1,
             instance_type=instance_type,
             endpoint_name=endpoint_name,
             # container_startup_health_check_timeout=3600,
            )
Step 3: Run inference¶
predictor.predict(
    {"inputs": "The future of Artificial Intelligence is", "parameters": {"max_new_tokens":128, "do_sample":"true"}}
)
Clean up the environment¶
session.delete_endpoint(endpoint_name)
session.delete_endpoint_config(endpoint_name)
model.delete_model()