Skip to content
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(stepfunctions-tasks): add support for SageMakerCreateTransformJob to take instance type as a parameter #14064

Closed
wants to merge 6 commits into from

Conversation

PPPW
Copy link

@PPPW PPPW commented Apr 8, 2021

Currently to create a SageMaker Batch Transform job, we can't specify the instance type as a parameter (e.g., 'InstanceType.$': '$.InstanceType' in CFN template), because the TransformResources.instanceType is of type ec2.InstanceType, and we will add a "ml." prefix to this EC2 instance type as the final instance type. We'd like to build step functions with SageMaker Batch Transform state and be able to support different instance types from user input.

With this change, user can pass instance type as a parameter, with values such as "ml.p2.xlarge".


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Apr 8, 2021

@@ -638,7 +638,7 @@ export interface TransformResources {
/**
* ML compute instance type for the transform job.
*/
readonly instanceType: ec2.InstanceType;
readonly instanceType: ec2.InstanceType | string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript union types will not be compatible with other languages.
This will need to be represented by a single type. The way we do it in the cdk is to create a union like class with APIs like fromInstanceType and fromString that return that type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I can define a instanceType class here to use it as the type of this field, something like this:

export class InstanceType {
  public static fromEc2InstanceType(instanceType: ec2.InstanceType) {
    return new InstanceType(`ml.${instanceType}`);
  }

  public static fromString(instanceType: string) {
    return new InstanceType(instanceType);
  }

  constructor(private readonly instanceType: string) {
  }

  public toString(): string {
    return this.instanceType;
  }
}

But it won't be backward compatible, e.g. current users need to change their code: instanceType: ec2.InstanceType.of(ec2.InstanceClass.P3, ec2.InstanceSize.XLARGE2). Should we make it backward compatible somehow, or it's fine to do this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shivlaks, could you take a quick look at the above comments when you get a chance? Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shivlaks, looks like yarn compat is not happy with this change, because it changed the API. So should I make the InstanceType class defined in above to extend ec2. InstanceType?

@mergify mergify bot dismissed shivlaks’s stale review April 14, 2021 19:39

Pull request has been modified.

@PPPW
Copy link
Author

PPPW commented Apr 23, 2021

Dear @shivlaks, when you get a chance, could let me know if my fix looks fine? The instance type part is not backward compatible, I appreciate if you could provide some suggestions. Thank you for your time!

Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PPPW this looks good to me! a couple of minor things to take care of before we can merge. Let me know if you have any questions!

@gitpod-io
Copy link

gitpod-io bot commented May 23, 2021

@mergify mergify bot dismissed shivlaks’s stale review May 23, 2021 22:44

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: b3731c4
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending resolution re: breaking change from modifying type of instanceType from ec2.InstanceType to one that is defined locally within the module.

@@ -611,7 +611,7 @@ export interface TransformResources {
/**
* ML compute instance type for the transform job.
*/
readonly instanceType: ec2.InstanceType;
readonly instanceType: InstanceType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we removed the @experimental annotations after you had initially published this PR, but I believe this is now a breaking change.

Let me check with a team member or two to see whether we would need to:

  1. support the old parameter but mark it as @deprecated
  2. make this change as it is, but call it out as a BREAKING change.

It is a breaking change if we ship it as it is as clients who upgrade will see breakage.

Copy link
Author

@PPPW PPPW Jun 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, in earlier comments I was checking whether we should make it backward compatible. Let me know if we have to extend ec2. InstanceType here, thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shivlaks, any updates on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Shiv mentions above, we will need to create a new property (maybe mlInstanceType) and mark the old property as deprecated. Unfortunately we cannot extend this type with a type union due to jsii restrictions

@BenChaimberg
Copy link
Contributor

This will probably be superseded by #15726 as a simpler solution

@BenChaimberg BenChaimberg self-assigned this Jul 22, 2021
@PPPW
Copy link
Author

PPPW commented Jul 22, 2021

This will probably be superseded by #15726 as a simpler solution

Thanks @BenChaimberg, that looks good. Feel free to borrow my README and unit tests (or I can contribute if we'd like to).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants