skip to Main Content

With the AWS CLI ec2 describe-instance-types I can get a list of all the EC2 instance types but Sagemaker Instance Types like ml.t3.medium, ml.t3.large, ml.m5.xlarge, etc are not there.

aws ec2 describe-instance-types --filters "Name=instance-type,Values=ml.*" --query "InstanceTypes[].{Type: InstanceType, MaxENI: NetworkInfo.MaximumNetworkInterfaces, IPv4addr: NetworkInfo.Ipv4AddressesPerInterface}" --output table
# returns no results

I know I can get the list of SageMaker Instance Types from https://aws.amazon.com/sagemaker/pricing/ but I really want to get it programmatically.

How can I get programatically the list of instance types supported in Sagemaker for a given region?

2

Answers


  1. Chosen as BEST ANSWER

    Building upon the answer from Gili.

    Using the aws CLI and jq :

    aws --region us-east-1 pricing get-products 
      --service-code AmazonSageMaker 
      --filters Type=TERM_MATCH,Field=regionCode,Value=eu-north-1 
      | jq -r '.PriceList[]|fromjson|select(.product.productFamily == "ML Instance")|.product.attributes.instanceName'
    |sort
    |uniq
    
    ml.c5.12xlarge
    ml.c5.18xlarge
    ml.c5.24xlarge
    ml.c5.2xlarge
    ml.c5.4xlarge
    ml.c5.9xlarge
    ml.c5.large
    ...
    ml.t3.2xlarge
    ml.t3.large
    ml.t3.medium
    ml.t3.xlarge
    

    it uses

    • aws pricing get-products
      • --region us-east-1 is important because the Pricing service is not widely available
      • --filters Type=TERM_MATCH,Field=regionCode,Values=eu-north-1 to restrict the listing to products in eu-north-1 region, the number of products for AmazonSageMaker alone across all regions is huge, so better to let AWS to filter out those early
    • jq is used to further filter the output, it seems it's not possible to filter by productFamily at the aws pricing get-products so we need to do it with jq
      • -r removes the quotes from the output
      • .PriceList[] will iterate over all the prices returned by aws pricing get-products
      • fromjson will parse the each string as JSON (.PriceList is an array of strings)
      • select(.product.productFamily == "ML Instance") will filter out all other products
      • .product.attributes.instanceName extracts the instance type from each product.

  2. You can get the list of ml instances with this CLI call (doc):

    aws pricing get-products --service-code AmazonSageMaker --filters Type=TERM_MATCH,Field=location,Value="US East (N. Virginia)"
    

    You’ll need to filter the results further.
    Note that a particular ml instance type might be available for a certain SageMaker feature like training, but not for inference. And be available in one region but not another.

    If you’re end goal is to get technical details, you could first fine the relevant ml.* instances (maybe even with regex), then use the EC2 describe instance type to get more details (just strip down the ml. prefix).

    You can find relevant Python code in the "Total Cost" section of my notebook here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search