Skip to content

Commit d46ef3c

Browse files
SageMaker Neo now supports data input shape derivation for Pytorch 2.0 and XGBoost compilation job for cloud instance targets. You can skip DataInputConfig field during compilation job creation. You can also access derived information from model in DescribeCompilationJob response.
1 parent 8d4230e commit d46ef3c

File tree

10 files changed

+217
-8
lines changed

10 files changed

+217
-8
lines changed

generator/ServiceModels/sagemaker/sagemaker-2017-07-24.api.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7742,6 +7742,12 @@
77427742
"DeviceNames":{"shape":"DeviceNames"}
77437743
}
77447744
},
7745+
"DerivedInformation":{
7746+
"type":"structure",
7747+
"members":{
7748+
"DerivedDataInputConfig":{"shape":"DataInputConfig"}
7749+
}
7750+
},
77457751
"DescribeActionRequest":{
77467752
"type":"structure",
77477753
"required":["ActionName"],
@@ -8021,7 +8027,8 @@
80218027
"RoleArn":{"shape":"RoleArn"},
80228028
"InputConfig":{"shape":"InputConfig"},
80238029
"OutputConfig":{"shape":"OutputConfig"},
8024-
"VpcConfig":{"shape":"NeoVpcConfig"}
8030+
"VpcConfig":{"shape":"NeoVpcConfig"},
8031+
"DerivedInformation":{"shape":"DerivedInformation"}
80258032
}
80268033
},
80278034
"DescribeContextRequest":{
@@ -12255,7 +12262,6 @@
1225512262
"type":"structure",
1225612263
"required":[
1225712264
"S3Uri",
12258-
"DataInputConfig",
1225912265
"Framework"
1226012266
],
1226112267
"members":{

generator/ServiceModels/sagemaker/sagemaker-2017-07-24.docs.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,6 +2950,7 @@
29502950
"DataInputConfig": {
29512951
"base": null,
29522952
"refs": {
2953+
"DerivedInformation$DerivedDataInputConfig": "<p>The data input configuration that SageMaker Neo automatically derived for the model. When SageMaker Neo derives this information, you don't need to specify the data input configuration when you create a compilation job.</p>",
29532954
"InputConfig$DataInputConfig": "<p>Specifies the name and shape of the expected data inputs for your trained model with a JSON dictionary form. The data inputs are <code>Framework</code> specific. </p> <ul> <li> <p> <code>TensorFlow</code>: You must specify the name and shape (NHWC format) of the expected data inputs using a dictionary format for your trained model. The dictionary formats required for the console and CLI are different.</p> <ul> <li> <p>Examples for one input:</p> <ul> <li> <p>If using the console, <code>{\"input\":[1,1024,1024,3]}</code> </p> </li> <li> <p>If using the CLI, <code>{\\\"input\\\":[1,1024,1024,3]}</code> </p> </li> </ul> </li> <li> <p>Examples for two inputs:</p> <ul> <li> <p>If using the console, <code>{\"data1\": [1,28,28,1], \"data2\":[1,28,28,1]}</code> </p> </li> <li> <p>If using the CLI, <code>{\\\"data1\\\": [1,28,28,1], \\\"data2\\\":[1,28,28,1]}</code> </p> </li> </ul> </li> </ul> </li> <li> <p> <code>KERAS</code>: You must specify the name and shape (NCHW format) of expected data inputs using a dictionary format for your trained model. Note that while Keras model artifacts should be uploaded in NHWC (channel-last) format, <code>DataInputConfig</code> should be specified in NCHW (channel-first) format. The dictionary formats required for the console and CLI are different.</p> <ul> <li> <p>Examples for one input:</p> <ul> <li> <p>If using the console, <code>{\"input_1\":[1,3,224,224]}</code> </p> </li> <li> <p>If using the CLI, <code>{\\\"input_1\\\":[1,3,224,224]}</code> </p> </li> </ul> </li> <li> <p>Examples for two inputs:</p> <ul> <li> <p>If using the console, <code>{\"input_1\": [1,3,224,224], \"input_2\":[1,3,224,224]} </code> </p> </li> <li> <p>If using the CLI, <code>{\\\"input_1\\\": [1,3,224,224], \\\"input_2\\\":[1,3,224,224]}</code> </p> </li> </ul> </li> </ul> </li> <li> <p> <code>MXNET/ONNX/DARKNET</code>: You must specify the name and shape (NCHW format) of the expected data inputs in order using a dictionary format for your trained model. The dictionary formats required for the console and CLI are different.</p> <ul> <li> <p>Examples for one input:</p> <ul> <li> <p>If using the console, <code>{\"data\":[1,3,1024,1024]}</code> </p> </li> <li> <p>If using the CLI, <code>{\\\"data\\\":[1,3,1024,1024]}</code> </p> </li> </ul> </li> <li> <p>Examples for two inputs:</p> <ul> <li> <p>If using the console, <code>{\"var1\": [1,1,28,28], \"var2\":[1,1,28,28]} </code> </p> </li> <li> <p>If using the CLI, <code>{\\\"var1\\\": [1,1,28,28], \\\"var2\\\":[1,1,28,28]}</code> </p> </li> </ul> </li> </ul> </li> <li> <p> <code>PyTorch</code>: You can either specify the name and shape (NCHW format) of expected data inputs in order using a dictionary format for your trained model or you can specify the shape only using a list format. The dictionary formats required for the console and CLI are different. The list formats for the console and CLI are the same.</p> <ul> <li> <p>Examples for one input in dictionary format:</p> <ul> <li> <p>If using the console, <code>{\"input0\":[1,3,224,224]}</code> </p> </li> <li> <p>If using the CLI, <code>{\\\"input0\\\":[1,3,224,224]}</code> </p> </li> </ul> </li> <li> <p>Example for one input in list format: <code>[[1,3,224,224]]</code> </p> </li> <li> <p>Examples for two inputs in dictionary format:</p> <ul> <li> <p>If using the console, <code>{\"input0\":[1,3,224,224], \"input1\":[1,3,224,224]}</code> </p> </li> <li> <p>If using the CLI, <code>{\\\"input0\\\":[1,3,224,224], \\\"input1\\\":[1,3,224,224]} </code> </p> </li> </ul> </li> <li> <p>Example for two inputs in list format: <code>[[1,3,224,224], [1,3,224,224]]</code> </p> </li> </ul> </li> <li> <p> <code>XGBOOST</code>: input data name and shape are not needed.</p> </li> </ul> <p> <code>DataInputConfig</code> supports the following parameters for <code>CoreML</code> <code>TargetDevice</code> (ML Model format):</p> <ul> <li> <p> <code>shape</code>: Input shape, for example <code>{\"input_1\": {\"shape\": [1,224,224,3]}}</code>. In addition to static input shapes, CoreML converter supports Flexible input shapes:</p> <ul> <li> <p>Range Dimension. You can use the Range Dimension feature if you know the input shape will be within some specific interval in that dimension, for example: <code>{\"input_1\": {\"shape\": [\"1..10\", 224, 224, 3]}}</code> </p> </li> <li> <p>Enumerated shapes. Sometimes, the models are trained to work only on a select set of inputs. You can enumerate all supported input shapes, for example: <code>{\"input_1\": {\"shape\": [[1, 224, 224, 3], [1, 160, 160, 3]]}}</code> </p> </li> </ul> </li> <li> <p> <code>default_shape</code>: Default input shape. You can set a default shape during conversion for both Range Dimension and Enumerated Shapes. For example <code>{\"input_1\": {\"shape\": [\"1..10\", 224, 224, 3], \"default_shape\": [1, 224, 224, 3]}}</code> </p> </li> <li> <p> <code>type</code>: Input type. Allowed values: <code>Image</code> and <code>Tensor</code>. By default, the converter generates an ML Model with inputs of type Tensor (MultiArray). User can set input type to be Image. Image input type requires additional input parameters such as <code>bias</code> and <code>scale</code>.</p> </li> <li> <p> <code>bias</code>: If the input type is an Image, you need to provide the bias vector.</p> </li> <li> <p> <code>scale</code>: If the input type is an Image, you need to provide a scale factor.</p> </li> </ul> <p>CoreML <code>ClassifierConfig</code> parameters can be specified using <a href=\"https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_OutputConfig.html\">OutputConfig</a> <code>CompilerOptions</code>. CoreML converter supports Tensorflow and PyTorch models. CoreML conversion examples:</p> <ul> <li> <p>Tensor type input:</p> <ul> <li> <p> <code>\"DataInputConfig\": {\"input_1\": {\"shape\": [[1,224,224,3], [1,160,160,3]], \"default_shape\": [1,224,224,3]}}</code> </p> </li> </ul> </li> <li> <p>Tensor type input without input name (PyTorch):</p> <ul> <li> <p> <code>\"DataInputConfig\": [{\"shape\": [[1,3,224,224], [1,3,160,160]], \"default_shape\": [1,3,224,224]}]</code> </p> </li> </ul> </li> <li> <p>Image type input:</p> <ul> <li> <p> <code>\"DataInputConfig\": {\"input_1\": {\"shape\": [[1,224,224,3], [1,160,160,3]], \"default_shape\": [1,224,224,3], \"type\": \"Image\", \"bias\": [-1,-1,-1], \"scale\": 0.007843137255}}</code> </p> </li> <li> <p> <code>\"CompilerOptions\": {\"class_labels\": \"imagenet_labels_1000.txt\"}</code> </p> </li> </ul> </li> <li> <p>Image type input without input name (PyTorch):</p> <ul> <li> <p> <code>\"DataInputConfig\": [{\"shape\": [[1,3,224,224], [1,3,160,160]], \"default_shape\": [1,3,224,224], \"type\": \"Image\", \"bias\": [-1,-1,-1], \"scale\": 0.007843137255}]</code> </p> </li> <li> <p> <code>\"CompilerOptions\": {\"class_labels\": \"imagenet_labels_1000.txt\"}</code> </p> </li> </ul> </li> </ul> <p>Depending on the model format, <code>DataInputConfig</code> requires the following parameters for <code>ml_eia2</code> <a href=\"https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_OutputConfig.html#sagemaker-Type-OutputConfig-TargetDevice\">OutputConfig:TargetDevice</a>.</p> <ul> <li> <p>For TensorFlow models saved in the SavedModel format, specify the input names from <code>signature_def_key</code> and the input model shapes for <code>DataInputConfig</code>. Specify the <code>signature_def_key</code> in <a href=\"https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_OutputConfig.html#sagemaker-Type-OutputConfig-CompilerOptions\"> <code>OutputConfig:CompilerOptions</code> </a> if the model does not use TensorFlow's default signature def key. For example:</p> <ul> <li> <p> <code>\"DataInputConfig\": {\"inputs\": [1, 224, 224, 3]}</code> </p> </li> <li> <p> <code>\"CompilerOptions\": {\"signature_def_key\": \"serving_custom\"}</code> </p> </li> </ul> </li> <li> <p>For TensorFlow models saved as a frozen graph, specify the input tensor names and shapes in <code>DataInputConfig</code> and the output tensor names for <code>output_names</code> in <a href=\"https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_OutputConfig.html#sagemaker-Type-OutputConfig-CompilerOptions\"> <code>OutputConfig:CompilerOptions</code> </a>. For example:</p> <ul> <li> <p> <code>\"DataInputConfig\": {\"input_tensor:0\": [1, 224, 224, 3]}</code> </p> </li> <li> <p> <code>\"CompilerOptions\": {\"output_names\": [\"output_tensor:0\"]}</code> </p> </li> </ul> </li> </ul>",
29542955
"ModelInput$DataInputConfig": "<p>The input configuration object for the model.</p>"
29552956
}
@@ -3443,6 +3444,12 @@
34433444
"refs": {
34443445
}
34453446
},
3447+
"DerivedInformation": {
3448+
"base": "<p>Information that SageMaker Neo automatically derived about the model.</p>",
3449+
"refs": {
3450+
"DescribeCompilationJobResponse$DerivedInformation": "<p>Information that SageMaker Neo automatically derived about the model.</p>"
3451+
}
3452+
},
34463453
"DescribeActionRequest": {
34473454
"base": null,
34483455
"refs": {
@@ -13178,7 +13185,7 @@
1317813185
"refs": {
1317913186
"ActionSummary$ActionType": "<p>The type of the action.</p>",
1318013187
"CategoricalParameter$Name": "<p>The Name of the environment variable.</p>",
13181-
"ModelLatencyThreshold$Percentile": "<p>The model latency percentile threshold. For custom load tests, specify the value as <code>P95</code>.</p>"
13188+
"ModelLatencyThreshold$Percentile": "<p>The model latency percentile threshold. Acceptable values are <code>P95</code> and <code>P99</code>. For custom load tests, specify the value as <code>P95</code>.</p>"
1318213189
}
1318313190
},
1318413191
"String8192": {

generator/ServiceModels/sagemaker/sagemaker-2017-07-24.normal.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10852,6 +10852,16 @@
1085210852
}
1085310853
}
1085410854
},
10855+
"DerivedInformation":{
10856+
"type":"structure",
10857+
"members":{
10858+
"DerivedDataInputConfig":{
10859+
"shape":"DataInputConfig",
10860+
"documentation":"<p>The data input configuration that SageMaker Neo automatically derived for the model. When SageMaker Neo derives this information, you don't need to specify the data input configuration when you create a compilation job.</p>"
10861+
}
10862+
},
10863+
"documentation":"<p>Information that SageMaker Neo automatically derived about the model.</p>"
10864+
},
1085510865
"DescribeActionRequest":{
1085610866
"type":"structure",
1085710867
"required":["ActionName"],
@@ -11500,6 +11510,10 @@
1150011510
"VpcConfig":{
1150111511
"shape":"NeoVpcConfig",
1150211512
"documentation":"<p>A <a href=\"https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_VpcConfig.html\">VpcConfig</a> object that specifies the VPC that you want your compilation job to connect to. Control access to your models by configuring the VPC. For more information, see <a href=\"https://docs.aws.amazon.com/sagemaker/latest/dg/neo-vpc.html\">Protect Compilation Jobs by Using an Amazon Virtual Private Cloud</a>.</p>"
11513+
},
11514+
"DerivedInformation":{
11515+
"shape":"DerivedInformation",
11516+
"documentation":"<p>Information that SageMaker Neo automatically derived about the model.</p>"
1150311517
}
1150411518
}
1150511519
},
@@ -19173,7 +19187,6 @@
1917319187
"type":"structure",
1917419188
"required":[
1917519189
"S3Uri",
19176-
"DataInputConfig",
1917719190
"Framework"
1917819191
],
1917919192
"members":{
@@ -24767,7 +24780,7 @@
2476724780
"members":{
2476824781
"Percentile":{
2476924782
"shape":"String64",
24770-
"documentation":"<p>The model latency percentile threshold. For custom load tests, specify the value as <code>P95</code>.</p>"
24783+
"documentation":"<p>The model latency percentile threshold. Acceptable values are <code>P95</code> and <code>P99</code>. For custom load tests, specify the value as <code>P95</code>.</p>"
2477124784
},
2477224785
"ValueInMilliseconds":{
2477324786
"shape":"Integer",

sdk/code-analysis/ServiceAnalysis/SageMaker/Generated/PropertyValueRules.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6923,6 +6923,12 @@
69236923
<max>63</max>
69246924
<pattern>^[a-zA-Z0-9](-*[a-zA-Z0-9]){0,62}$</pattern>
69256925
</property-value-rule>
6926+
<property-value-rule>
6927+
<property>Amazon.SageMaker.Model.DerivedInformation.DerivedDataInputConfig</property>
6928+
<min>1</min>
6929+
<max>1024</max>
6930+
<pattern>[\S\s]+</pattern>
6931+
</property-value-rule>
69266932
<property-value-rule>
69276933
<property>Amazon.SageMaker.Model.DesiredWeightAndCapacity.DesiredInstanceCount</property>
69286934
<min>0</min>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
/*
17+
* Do not modify this file. This file is generated from the sagemaker-2017-07-24.normal.json service model.
18+
*/
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Xml.Serialization;
22+
using System.Text;
23+
using System.IO;
24+
using System.Net;
25+
26+
using Amazon.Runtime;
27+
using Amazon.Runtime.Internal;
28+
29+
namespace Amazon.SageMaker.Model
30+
{
31+
/// <summary>
32+
/// Information that SageMaker Neo automatically derived about the model.
33+
/// </summary>
34+
public partial class DerivedInformation
35+
{
36+
private string _derivedDataInputConfig;
37+
38+
/// <summary>
39+
/// Gets and sets the property DerivedDataInputConfig.
40+
/// <para>
41+
/// The data input configuration that SageMaker Neo automatically derived for the model.
42+
/// When SageMaker Neo derives this information, you don't need to specify the data input
43+
/// configuration when you create a compilation job.
44+
/// </para>
45+
/// </summary>
46+
[AWSProperty(Min=1, Max=1024)]
47+
public string DerivedDataInputConfig
48+
{
49+
get { return this._derivedDataInputConfig; }
50+
set { this._derivedDataInputConfig = value; }
51+
}
52+
53+
// Check to see if DerivedDataInputConfig property is set
54+
internal bool IsSetDerivedDataInputConfig()
55+
{
56+
return this._derivedDataInputConfig != null;
57+
}
58+
59+
}
60+
}

sdk/src/Services/SageMaker/Generated/Model/DescribeCompilationJobResponse.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public partial class DescribeCompilationJobResponse : AmazonWebServiceResponse
3939
private CompilationJobStatus _compilationJobStatus;
4040
private DateTime? _compilationStartTime;
4141
private DateTime? _creationTime;
42+
private DerivedInformation _derivedInformation;
4243
private string _failureReason;
4344
private string _inferenceImage;
4445
private InputConfig _inputConfig;
@@ -173,6 +174,24 @@ internal bool IsSetCreationTime()
173174
return this._creationTime.HasValue;
174175
}
175176

177+
/// <summary>
178+
/// Gets and sets the property DerivedInformation.
179+
/// <para>
180+
/// Information that SageMaker Neo automatically derived about the model.
181+
/// </para>
182+
/// </summary>
183+
public DerivedInformation DerivedInformation
184+
{
185+
get { return this._derivedInformation; }
186+
set { this._derivedInformation = value; }
187+
}
188+
189+
// Check to see if DerivedInformation property is set
190+
internal bool IsSetDerivedInformation()
191+
{
192+
return this._derivedInformation != null;
193+
}
194+
176195
/// <summary>
177196
/// Gets and sets the property FailureReason.
178197
/// <para>

sdk/src/Services/SageMaker/Generated/Model/InputConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public partial class InputConfig
319319
/// </para>
320320
/// </li> </ul> </li> </ul>
321321
/// </summary>
322-
[AWSProperty(Required=true, Min=1, Max=1024)]
322+
[AWSProperty(Min=1, Max=1024)]
323323
public string DataInputConfig
324324
{
325325
get { return this._dataInputConfig; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
/*
17+
* Do not modify this file. This file is generated from the sagemaker-2017-07-24.normal.json service model.
18+
*/
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Globalization;
22+
using System.IO;
23+
using System.Net;
24+
using System.Text;
25+
using System.Xml.Serialization;
26+
27+
using Amazon.SageMaker.Model;
28+
using Amazon.Runtime;
29+
using Amazon.Runtime.Internal;
30+
using Amazon.Runtime.Internal.Transform;
31+
using Amazon.Runtime.Internal.Util;
32+
using ThirdParty.Json.LitJson;
33+
34+
namespace Amazon.SageMaker.Model.Internal.MarshallTransformations
35+
{
36+
/// <summary>
37+
/// Response Unmarshaller for DerivedInformation Object
38+
/// </summary>
39+
public class DerivedInformationUnmarshaller : IUnmarshaller<DerivedInformation, XmlUnmarshallerContext>, IUnmarshaller<DerivedInformation, JsonUnmarshallerContext>
40+
{
41+
/// <summary>
42+
/// Unmarshaller the response from the service to the response class.
43+
/// </summary>
44+
/// <param name="context"></param>
45+
/// <returns></returns>
46+
DerivedInformation IUnmarshaller<DerivedInformation, XmlUnmarshallerContext>.Unmarshall(XmlUnmarshallerContext context)
47+
{
48+
throw new NotImplementedException();
49+
}
50+
51+
/// <summary>
52+
/// Unmarshaller the response from the service to the response class.
53+
/// </summary>
54+
/// <param name="context"></param>
55+
/// <returns></returns>
56+
public DerivedInformation Unmarshall(JsonUnmarshallerContext context)
57+
{
58+
context.Read();
59+
if (context.CurrentTokenType == JsonToken.Null)
60+
return null;
61+
62+
DerivedInformation unmarshalledObject = new DerivedInformation();
63+
64+
int targetDepth = context.CurrentDepth;
65+
while (context.ReadAtDepth(targetDepth))
66+
{
67+
if (context.TestExpression("DerivedDataInputConfig", targetDepth))
68+
{
69+
var unmarshaller = StringUnmarshaller.Instance;
70+
unmarshalledObject.DerivedDataInputConfig = unmarshaller.Unmarshall(context);
71+
continue;
72+
}
73+
}
74+
75+
return unmarshalledObject;
76+
}
77+
78+
79+
private static DerivedInformationUnmarshaller _instance = new DerivedInformationUnmarshaller();
80+
81+
/// <summary>
82+
/// Gets the singleton.
83+
/// </summary>
84+
public static DerivedInformationUnmarshaller Instance
85+
{
86+
get
87+
{
88+
return _instance;
89+
}
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)