@aws/ml-container-creator 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/LICENSE-THIRD-PARTY +68620 -0
- package/NOTICE +2 -0
- package/README.md +106 -0
- package/bin/cli.js +365 -0
- package/config/defaults.json +32 -0
- package/config/presets/transformers-djl.json +26 -0
- package/config/presets/transformers-gpu.json +24 -0
- package/config/presets/transformers-lmi.json +27 -0
- package/package.json +129 -0
- package/servers/README.md +419 -0
- package/servers/base-image-picker/catalogs/model-servers.json +1191 -0
- package/servers/base-image-picker/catalogs/python-slim.json +38 -0
- package/servers/base-image-picker/catalogs/triton-backends.json +51 -0
- package/servers/base-image-picker/catalogs/triton.json +38 -0
- package/servers/base-image-picker/index.js +495 -0
- package/servers/base-image-picker/manifest.json +17 -0
- package/servers/base-image-picker/package.json +15 -0
- package/servers/hyperpod-cluster-picker/LICENSE +202 -0
- package/servers/hyperpod-cluster-picker/index.js +424 -0
- package/servers/hyperpod-cluster-picker/manifest.json +14 -0
- package/servers/hyperpod-cluster-picker/package.json +17 -0
- package/servers/instance-recommender/LICENSE +202 -0
- package/servers/instance-recommender/catalogs/instances.json +852 -0
- package/servers/instance-recommender/index.js +284 -0
- package/servers/instance-recommender/manifest.json +16 -0
- package/servers/instance-recommender/package.json +15 -0
- package/servers/lib/LICENSE +202 -0
- package/servers/lib/bedrock-client.js +160 -0
- package/servers/lib/custom-validators.js +46 -0
- package/servers/lib/dynamic-resolver.js +36 -0
- package/servers/lib/package.json +11 -0
- package/servers/lib/schemas/image-catalog.schema.json +185 -0
- package/servers/lib/schemas/instances.schema.json +124 -0
- package/servers/lib/schemas/manifest.schema.json +64 -0
- package/servers/lib/schemas/model-catalog.schema.json +91 -0
- package/servers/lib/schemas/regions.schema.json +26 -0
- package/servers/lib/schemas/triton-backends.schema.json +51 -0
- package/servers/model-picker/catalogs/jumpstart-public.json +66 -0
- package/servers/model-picker/catalogs/popular-diffusors.json +88 -0
- package/servers/model-picker/catalogs/popular-transformers.json +226 -0
- package/servers/model-picker/index.js +1693 -0
- package/servers/model-picker/manifest.json +18 -0
- package/servers/model-picker/package.json +20 -0
- package/servers/region-picker/LICENSE +202 -0
- package/servers/region-picker/catalogs/regions.json +263 -0
- package/servers/region-picker/index.js +230 -0
- package/servers/region-picker/manifest.json +16 -0
- package/servers/region-picker/package.json +15 -0
- package/src/app.js +1007 -0
- package/src/copy-tpl.js +77 -0
- package/src/lib/accelerator-validator.js +39 -0
- package/src/lib/asset-manager.js +385 -0
- package/src/lib/aws-profile-parser.js +181 -0
- package/src/lib/bootstrap-command-handler.js +1647 -0
- package/src/lib/bootstrap-config.js +238 -0
- package/src/lib/ci-register-helpers.js +124 -0
- package/src/lib/ci-report-helpers.js +158 -0
- package/src/lib/ci-stage-helpers.js +268 -0
- package/src/lib/cli-handler.js +529 -0
- package/src/lib/comment-generator.js +544 -0
- package/src/lib/community-reports-validator.js +91 -0
- package/src/lib/config-manager.js +2106 -0
- package/src/lib/configuration-exporter.js +204 -0
- package/src/lib/configuration-manager.js +695 -0
- package/src/lib/configuration-matcher.js +221 -0
- package/src/lib/cpu-validator.js +36 -0
- package/src/lib/cuda-validator.js +57 -0
- package/src/lib/deployment-config-resolver.js +103 -0
- package/src/lib/deployment-entry-schema.js +125 -0
- package/src/lib/deployment-registry.js +598 -0
- package/src/lib/docker-introspection-validator.js +51 -0
- package/src/lib/engine-prefix-resolver.js +60 -0
- package/src/lib/huggingface-client.js +172 -0
- package/src/lib/key-value-parser.js +37 -0
- package/src/lib/known-flags-validator.js +200 -0
- package/src/lib/manifest-cli.js +280 -0
- package/src/lib/mcp-client.js +303 -0
- package/src/lib/mcp-command-handler.js +532 -0
- package/src/lib/neuron-validator.js +80 -0
- package/src/lib/parameter-schema-validator.js +284 -0
- package/src/lib/prompt-runner.js +1349 -0
- package/src/lib/prompts.js +1138 -0
- package/src/lib/registry-command-handler.js +519 -0
- package/src/lib/registry-loader.js +198 -0
- package/src/lib/rocm-validator.js +80 -0
- package/src/lib/schema-validator.js +157 -0
- package/src/lib/sensitive-redactor.js +59 -0
- package/src/lib/template-engine.js +156 -0
- package/src/lib/template-manager.js +341 -0
- package/src/lib/validation-engine.js +314 -0
- package/src/prompt-adapter.js +63 -0
- package/templates/Dockerfile +300 -0
- package/templates/IAM_PERMISSIONS.md +84 -0
- package/templates/MIGRATION.md +488 -0
- package/templates/PROJECT_README.md +439 -0
- package/templates/TEMPLATE_SYSTEM.md +243 -0
- package/templates/buildspec.yml +64 -0
- package/templates/code/chat_template.jinja +1 -0
- package/templates/code/flask/gunicorn_config.py +35 -0
- package/templates/code/flask/wsgi.py +10 -0
- package/templates/code/model_handler.py +387 -0
- package/templates/code/serve +300 -0
- package/templates/code/serve.py +175 -0
- package/templates/code/serving.properties +105 -0
- package/templates/code/start_server.py +39 -0
- package/templates/code/start_server.sh +39 -0
- package/templates/diffusors/Dockerfile +72 -0
- package/templates/diffusors/patch_image_api.py +35 -0
- package/templates/diffusors/serve +115 -0
- package/templates/diffusors/start_server.sh +114 -0
- package/templates/do/.gitkeep +1 -0
- package/templates/do/README.md +541 -0
- package/templates/do/build +83 -0
- package/templates/do/ci +681 -0
- package/templates/do/clean +811 -0
- package/templates/do/config +260 -0
- package/templates/do/deploy +1560 -0
- package/templates/do/export +306 -0
- package/templates/do/logs +319 -0
- package/templates/do/manifest +12 -0
- package/templates/do/push +119 -0
- package/templates/do/register +580 -0
- package/templates/do/run +113 -0
- package/templates/do/submit +417 -0
- package/templates/do/test +1147 -0
- package/templates/hyperpod/configmap.yaml +24 -0
- package/templates/hyperpod/deployment.yaml +71 -0
- package/templates/hyperpod/pvc.yaml +42 -0
- package/templates/hyperpod/service.yaml +17 -0
- package/templates/nginx-diffusors.conf +74 -0
- package/templates/nginx-predictors.conf +47 -0
- package/templates/nginx-tensorrt.conf +74 -0
- package/templates/requirements.txt +61 -0
- package/templates/sample_model/test_inference.py +123 -0
- package/templates/sample_model/train_abalone.py +252 -0
- package/templates/test/test_endpoint.sh +79 -0
- package/templates/test/test_local_image.sh +80 -0
- package/templates/test/test_model_handler.py +180 -0
- package/templates/triton/Dockerfile +128 -0
- package/templates/triton/config.pbtxt +163 -0
- package/templates/triton/model.py +130 -0
- package/templates/triton/requirements.txt +11 -0
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* CLI Handler - Handles special CLI arguments and commands
|
|
6
|
+
*
|
|
7
|
+
* Supports behavioral CLI arguments like:
|
|
8
|
+
* - ml-container-creator configure
|
|
9
|
+
* - ml-container-creator generate-empty-config
|
|
10
|
+
* - ml-container-creator --help
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import fs from 'fs';
|
|
14
|
+
// import path from 'path'; // Unused import removed
|
|
15
|
+
import McpCommandHandler from './mcp-command-handler.js';
|
|
16
|
+
|
|
17
|
+
export default class CliHandler {
|
|
18
|
+
constructor(generator) {
|
|
19
|
+
this.generator = generator;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Handles special CLI arguments
|
|
24
|
+
* @returns {boolean} True if special command was handled, false to continue normal flow
|
|
25
|
+
*/
|
|
26
|
+
async handleCliArguments() {
|
|
27
|
+
const args = this.generator.args;
|
|
28
|
+
const options = this.generator.options;
|
|
29
|
+
|
|
30
|
+
// Check for help flags in options first
|
|
31
|
+
if (options.help || options.h) {
|
|
32
|
+
this._showHelp();
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (args.length === 0) {
|
|
37
|
+
return false; // Normal generation flow
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const command = args[0].toLowerCase();
|
|
41
|
+
|
|
42
|
+
switch (command) {
|
|
43
|
+
case 'configure':
|
|
44
|
+
await this._handleConfigure();
|
|
45
|
+
return true;
|
|
46
|
+
|
|
47
|
+
case 'generate-empty-config':
|
|
48
|
+
await this._handleGenerateEmptyConfig();
|
|
49
|
+
return true;
|
|
50
|
+
|
|
51
|
+
case 'mcp': {
|
|
52
|
+
const mcpHandler = new McpCommandHandler(this.generator);
|
|
53
|
+
await mcpHandler.handle(args.slice(1), options);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
case 'registry': {
|
|
58
|
+
const { default: RegistryCommandHandler } = await import('./registry-command-handler.js');
|
|
59
|
+
const registryHandler = new RegistryCommandHandler();
|
|
60
|
+
await registryHandler.handle(args.slice(1), options);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
case 'bootstrap': {
|
|
65
|
+
const { default: BootstrapCommandHandler } = await import('./bootstrap-command-handler.js');
|
|
66
|
+
const bootstrapHandler = new BootstrapCommandHandler();
|
|
67
|
+
await bootstrapHandler.handle(args.slice(1), options);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
case 'help':
|
|
72
|
+
case '--help':
|
|
73
|
+
case '-h':
|
|
74
|
+
this._showHelp();
|
|
75
|
+
return true;
|
|
76
|
+
|
|
77
|
+
default:
|
|
78
|
+
// If it's not a special command, treat as project name
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Interactive configuration setup
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
async _handleConfigure() {
|
|
88
|
+
console.log('\n🔧 ML Container Creator Configuration');
|
|
89
|
+
console.log('\nThis will help you set up configuration files for your project.\n');
|
|
90
|
+
|
|
91
|
+
const answers = await this.generator.prompt([
|
|
92
|
+
{
|
|
93
|
+
type: 'list',
|
|
94
|
+
name: 'configType',
|
|
95
|
+
message: 'What type of configuration would you like to create?',
|
|
96
|
+
choices: [
|
|
97
|
+
{ name: 'Package.json section (recommended for projects)', value: 'package' },
|
|
98
|
+
{ name: 'Custom config file (config/mcp.json)', value: 'custom' },
|
|
99
|
+
{ name: 'Show environment variable examples', value: 'env' },
|
|
100
|
+
{ name: 'Show CLI option examples', value: 'cli' }
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
switch (answers.configType) {
|
|
106
|
+
case 'package':
|
|
107
|
+
await this._createPackageJsonConfig();
|
|
108
|
+
break;
|
|
109
|
+
case 'custom':
|
|
110
|
+
await this._createCustomConfig();
|
|
111
|
+
break;
|
|
112
|
+
case 'env':
|
|
113
|
+
this._showEnvironmentExamples();
|
|
114
|
+
break;
|
|
115
|
+
case 'cli':
|
|
116
|
+
this._showCliExamples();
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Generate empty configuration file
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
async _handleGenerateEmptyConfig() {
|
|
126
|
+
const answers = await this.generator.prompt([
|
|
127
|
+
{
|
|
128
|
+
type: 'list',
|
|
129
|
+
name: 'configType',
|
|
130
|
+
message: 'Which configuration file format?',
|
|
131
|
+
choices: [
|
|
132
|
+
{ name: 'Custom config (config/mcp.json)', value: 'custom' }
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
const emptyConfig = this._getEmptyConfig();
|
|
138
|
+
|
|
139
|
+
if (answers.configType === 'custom') {
|
|
140
|
+
const configPath = 'config/mcp.json';
|
|
141
|
+
if (!fs.existsSync('config')) {
|
|
142
|
+
fs.mkdirSync('config', { recursive: true });
|
|
143
|
+
}
|
|
144
|
+
fs.writeFileSync(configPath, JSON.stringify(emptyConfig, null, 2));
|
|
145
|
+
console.log(`\n✅ Created empty configuration file: ${configPath}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
console.log('\n📝 Edit the configuration file and run the generator again.');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Show comprehensive help
|
|
153
|
+
* @private
|
|
154
|
+
*/
|
|
155
|
+
_showHelp() {
|
|
156
|
+
console.log(`
|
|
157
|
+
🚀 ML Container Creator Generator
|
|
158
|
+
|
|
159
|
+
USAGE:
|
|
160
|
+
ml-container-creator [command] [project-name] [options]
|
|
161
|
+
|
|
162
|
+
COMMANDS:
|
|
163
|
+
configure Interactive configuration setup
|
|
164
|
+
generate-empty-config Generate empty configuration file
|
|
165
|
+
bootstrap Set up shared AWS infrastructure (IAM role, ECR repo, S3 buckets)
|
|
166
|
+
help Show this help message
|
|
167
|
+
|
|
168
|
+
EXAMPLES:
|
|
169
|
+
ml-container-creator # Interactive mode
|
|
170
|
+
ml-container-creator my-project # With project name
|
|
171
|
+
ml-container-creator --skip-prompts # Skip prompts, use config
|
|
172
|
+
ml-container-creator --framework=sklearn # With CLI options
|
|
173
|
+
ml-container-creator --config=prod.json # With config file
|
|
174
|
+
|
|
175
|
+
CLI OPTIONS:
|
|
176
|
+
--skip-prompts Skip interactive prompts
|
|
177
|
+
--config=<file> Load configuration from file
|
|
178
|
+
--project-name=<name> Project name
|
|
179
|
+
--project-dir=<dir> Output directory path
|
|
180
|
+
--framework=<framework> ML framework (sklearn|xgboost|tensorflow|transformers)
|
|
181
|
+
--model-name=<name> HuggingFace model name (for transformers framework)
|
|
182
|
+
--model-server=<server> Model server (flask|fastapi|vllm|sglang|tensorrt-llm|lmi|djl)
|
|
183
|
+
--model-format=<format> Model format (depends on framework)
|
|
184
|
+
--include-sample Include sample model code
|
|
185
|
+
--include-testing Include test suite
|
|
186
|
+
--test-types=<types> Comma-separated test types (local-model-cli,local-model-server,hosted-model-endpoint)
|
|
187
|
+
--build-target=<target> Build target (codebuild)
|
|
188
|
+
--codebuild-compute-type=<type> CodeBuild compute type (BUILD_GENERAL1_SMALL|BUILD_GENERAL1_MEDIUM|BUILD_GENERAL1_LARGE)
|
|
189
|
+
--codebuild-project-name=<name> CodeBuild project name
|
|
190
|
+
--instance-type=<type> SageMaker instance type (e.g., ml.m5.large, ml.g5.xlarge)
|
|
191
|
+
--region=<region> AWS region
|
|
192
|
+
--role-arn=<arn> AWS IAM role ARN for SageMaker execution
|
|
193
|
+
--deployment-target=<target> Deployment target (managed-inference|hyperpod-eks)
|
|
194
|
+
--hyperpod-cluster=<name> HyperPod EKS cluster name
|
|
195
|
+
--hyperpod-namespace=<ns> Kubernetes namespace for HyperPod (default: default)
|
|
196
|
+
--hyperpod-replicas=<n> Number of replicas for HyperPod (default: 1)
|
|
197
|
+
--fsx-volume-handle=<id> FSx for Lustre volume handle for HyperPod storage
|
|
198
|
+
--hf-token=<token> HuggingFace token (or "$HF_TOKEN" for env var)
|
|
199
|
+
|
|
200
|
+
VALIDATION OPTIONS:
|
|
201
|
+
--validate-env-vars Enable environment variable validation (default: true)
|
|
202
|
+
--validate-with-docker Enable Docker introspection validation (default: false, opt-in)
|
|
203
|
+
--offline Disable HuggingFace API lookups (default: false)
|
|
204
|
+
|
|
205
|
+
MCP OPTIONS:
|
|
206
|
+
--smart Enable Bedrock-powered smart mode on all MCP servers
|
|
207
|
+
--discover Enable live registry lookups (e.g. Docker Hub) on MCP servers that support it
|
|
208
|
+
|
|
209
|
+
REGISTRY SYSTEM:
|
|
210
|
+
The generator includes built-in registries for frameworks, models, and instance types:
|
|
211
|
+
|
|
212
|
+
Framework Registry:
|
|
213
|
+
- Provides base images, environment variables, and accelerator requirements
|
|
214
|
+
- Supports version-specific configurations (e.g., vllm 0.3.0, 0.4.0)
|
|
215
|
+
- Includes optimization profiles (low-latency, high-throughput)
|
|
216
|
+
- Validates accelerator compatibility with instance types
|
|
217
|
+
|
|
218
|
+
Model Registry:
|
|
219
|
+
- Stores model-specific configurations and chat templates
|
|
220
|
+
- Supports pattern matching (e.g., "meta-llama/Llama-2-*")
|
|
221
|
+
- Provides recommended instance types per model
|
|
222
|
+
- Includes validation levels (tested, community-validated, experimental)
|
|
223
|
+
- Offers model profiles for different deployment scenarios
|
|
224
|
+
|
|
225
|
+
Instance Accelerator Mapping:
|
|
226
|
+
- Maps AWS instance types to accelerator capabilities
|
|
227
|
+
- Validates framework-instance compatibility
|
|
228
|
+
- Provides hardware specifications (GPU type, memory, vCPUs)
|
|
229
|
+
|
|
230
|
+
Registry Features:
|
|
231
|
+
- Automatic environment variable injection from registries
|
|
232
|
+
- Chat template detection from HuggingFace Hub or Model Registry
|
|
233
|
+
- Validation of framework-accelerator-instance compatibility
|
|
234
|
+
- Inline documentation comments in generated Dockerfiles
|
|
235
|
+
|
|
236
|
+
ENVIRONMENT VARIABLES:
|
|
237
|
+
ML_INSTANCE_TYPE Instance type
|
|
238
|
+
ML_BUILD_TARGET Build target
|
|
239
|
+
ML_CODEBUILD_COMPUTE_TYPE CodeBuild compute type
|
|
240
|
+
AWS_REGION AWS region
|
|
241
|
+
AWS_ROLE AWS IAM role ARN
|
|
242
|
+
ML_CONTAINER_CREATOR_CONFIG Config file path
|
|
243
|
+
VALIDATE_ENV_VARS Enable env var validation (true|false)
|
|
244
|
+
VALIDATE_WITH_DOCKER Enable Docker validation (true|false)
|
|
245
|
+
OFFLINE_MODE Disable HuggingFace API (true|false)
|
|
246
|
+
HF_TOKEN HuggingFace authentication token
|
|
247
|
+
|
|
248
|
+
CONFIGURATION FILES (in precedence order):
|
|
249
|
+
1. CLI options (highest precedence)
|
|
250
|
+
2. Environment variables
|
|
251
|
+
3. --config file
|
|
252
|
+
4. config/mcp.json
|
|
253
|
+
5. package.json "ml-container-creator" section
|
|
254
|
+
6. Registry defaults (framework/model registries)
|
|
255
|
+
7. Generator defaults
|
|
256
|
+
8. Interactive prompts (lowest precedence)
|
|
257
|
+
|
|
258
|
+
TRANSFORMER MODEL EXAMPLES:
|
|
259
|
+
# vLLM with Llama-2 7B
|
|
260
|
+
ml-container-creator --framework=transformers \\
|
|
261
|
+
--model-name=meta-llama/Llama-2-7b-chat-hf \\
|
|
262
|
+
--model-server=vllm \\
|
|
263
|
+
--instance-type=ml.g5.xlarge \\
|
|
264
|
+
--hf-token=$HF_TOKEN \\
|
|
265
|
+
--skip-prompts
|
|
266
|
+
|
|
267
|
+
# TensorRT-LLM with custom model
|
|
268
|
+
ml-container-creator --framework=transformers \\
|
|
269
|
+
--model-name=openai/gpt-oss-20b \\
|
|
270
|
+
--model-server=tensorrt-llm \\
|
|
271
|
+
--instance-type=ml.g6.12xlarge \\
|
|
272
|
+
--skip-prompts
|
|
273
|
+
|
|
274
|
+
# SGLang with Mistral
|
|
275
|
+
ml-container-creator --framework=transformers \\
|
|
276
|
+
--model-name=mistralai/Mistral-7B-Instruct-v0.2 \\
|
|
277
|
+
--model-server=sglang \\
|
|
278
|
+
--instance-type=ml.g5.xlarge \\
|
|
279
|
+
--skip-prompts
|
|
280
|
+
|
|
281
|
+
REGISTRY CONTRIBUTION:
|
|
282
|
+
To contribute to the catalogs:
|
|
283
|
+
- Framework Catalog: servers/base-image-picker/catalogs/model-servers.json
|
|
284
|
+
- Model Catalog: servers/model-picker/catalogs/popular-transformers.json
|
|
285
|
+
- Instance Catalog: servers/instance-recommender/catalogs/instances.json
|
|
286
|
+
|
|
287
|
+
See docs/REGISTRY_CONTRIBUTION_GUIDE.md for detailed contribution guidelines.
|
|
288
|
+
|
|
289
|
+
For more information, visit: https://github.com/awslabs/ml-container-creator
|
|
290
|
+
`);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Create package.json configuration section
|
|
295
|
+
* @private
|
|
296
|
+
*/
|
|
297
|
+
async _createPackageJsonConfig() {
|
|
298
|
+
const packageJsonPath = 'package.json';
|
|
299
|
+
let packageJson = {};
|
|
300
|
+
|
|
301
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
302
|
+
packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const config = await this._promptForConfig();
|
|
306
|
+
packageJson['ml-container-creator'] = config;
|
|
307
|
+
|
|
308
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
309
|
+
console.log(`\n✅ Added configuration to ${packageJsonPath}`);
|
|
310
|
+
console.log('\n📝 You can now run: ml-container-creator --skip-prompts');
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Create custom configuration file
|
|
315
|
+
* @private
|
|
316
|
+
*/
|
|
317
|
+
async _createCustomConfig() {
|
|
318
|
+
const config = await this._promptForConfig();
|
|
319
|
+
const configPath = 'config/mcp.json';
|
|
320
|
+
|
|
321
|
+
if (!fs.existsSync('config')) {
|
|
322
|
+
fs.mkdirSync('config', { recursive: true });
|
|
323
|
+
}
|
|
324
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
325
|
+
console.log(`\n✅ Created configuration file: ${configPath}`);
|
|
326
|
+
console.log('\n📝 You can now run: ml-container-creator --skip-prompts');
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Prompt for configuration values
|
|
333
|
+
* @private
|
|
334
|
+
*/
|
|
335
|
+
async _promptForConfig() {
|
|
336
|
+
return await this.generator.prompt([
|
|
337
|
+
{
|
|
338
|
+
type: 'input',
|
|
339
|
+
name: 'projectName',
|
|
340
|
+
message: 'Project name:',
|
|
341
|
+
default: 'my-ml-project'
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
type: 'list',
|
|
345
|
+
name: 'framework',
|
|
346
|
+
message: 'ML framework:',
|
|
347
|
+
choices: ['sklearn', 'xgboost', 'tensorflow', 'transformers']
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
type: 'list',
|
|
351
|
+
name: 'modelServer',
|
|
352
|
+
message: 'Model server:',
|
|
353
|
+
choices: (answers) => {
|
|
354
|
+
if (answers.framework === 'transformers') {
|
|
355
|
+
return ['vllm', 'sglang'];
|
|
356
|
+
}
|
|
357
|
+
return ['flask', 'fastapi'];
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
type: 'list',
|
|
362
|
+
name: 'modelFormat',
|
|
363
|
+
message: 'Model format:',
|
|
364
|
+
choices: (answers) => {
|
|
365
|
+
const formatMap = {
|
|
366
|
+
'xgboost': ['json', 'model', 'ubj'],
|
|
367
|
+
'sklearn': ['pkl', 'joblib'],
|
|
368
|
+
'tensorflow': ['keras', 'h5', 'SavedModel']
|
|
369
|
+
};
|
|
370
|
+
return formatMap[answers.framework] || [];
|
|
371
|
+
},
|
|
372
|
+
when: answers => answers.framework !== 'transformers'
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
type: 'confirm',
|
|
376
|
+
name: 'includeSampleModel',
|
|
377
|
+
message: 'Include sample model:',
|
|
378
|
+
default: false,
|
|
379
|
+
when: answers => answers.framework !== 'transformers'
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
type: 'confirm',
|
|
383
|
+
name: 'includeTesting',
|
|
384
|
+
message: 'Include testing:',
|
|
385
|
+
default: true
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
type: 'list',
|
|
389
|
+
name: 'instanceType',
|
|
390
|
+
message: 'Instance type:',
|
|
391
|
+
choices: (answers) => {
|
|
392
|
+
if (answers.framework === 'transformers') {
|
|
393
|
+
return ['ml.g5.xlarge'];
|
|
394
|
+
}
|
|
395
|
+
return ['ml.m5.large', 'ml.g5.xlarge'];
|
|
396
|
+
},
|
|
397
|
+
default: 'ml.m5.large'
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
type: 'list',
|
|
401
|
+
name: 'awsRegion',
|
|
402
|
+
message: 'AWS region:',
|
|
403
|
+
choices: ['us-east-1'],
|
|
404
|
+
default: 'us-east-1'
|
|
405
|
+
}
|
|
406
|
+
]);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Show environment variable examples
|
|
411
|
+
* @private
|
|
412
|
+
*/
|
|
413
|
+
_showEnvironmentExamples() {
|
|
414
|
+
console.log(`
|
|
415
|
+
🌍 Environment Variable Examples:
|
|
416
|
+
|
|
417
|
+
# Basic configuration
|
|
418
|
+
# Note: Core parameters (framework, model-server, etc.) are only supported via CLI options and config files
|
|
419
|
+
|
|
420
|
+
# Optional settings
|
|
421
|
+
export ML_INSTANCE_TYPE="ml.m5.large"
|
|
422
|
+
export AWS_REGION="us-east-1"
|
|
423
|
+
export AWS_ROLE="arn:aws:iam::123456789012:role/SageMakerRole"
|
|
424
|
+
export ML_CONTAINER_CREATOR_CONFIG="./my-config.json"
|
|
425
|
+
|
|
426
|
+
# Then run with CLI options for core parameters:
|
|
427
|
+
ml-container-creator --framework=sklearn --model-server=flask --model-format=pkl --skip-prompts
|
|
428
|
+
`);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Show CLI option examples
|
|
433
|
+
* @private
|
|
434
|
+
*/
|
|
435
|
+
_showCliExamples() {
|
|
436
|
+
console.log(`
|
|
437
|
+
💻 CLI Option Examples:
|
|
438
|
+
|
|
439
|
+
# Basic sklearn project
|
|
440
|
+
ml-container-creator my-sklearn-project \\
|
|
441
|
+
--framework=sklearn \\
|
|
442
|
+
--model-server=flask \\
|
|
443
|
+
--model-format=pkl \\
|
|
444
|
+
--skip-prompts
|
|
445
|
+
|
|
446
|
+
# Transformers project with vLLM
|
|
447
|
+
ml-container-creator my-llm-project \\
|
|
448
|
+
--framework=transformers \\
|
|
449
|
+
--model-name=meta-llama/Llama-2-7b-chat-hf \\
|
|
450
|
+
--model-server=vllm \\
|
|
451
|
+
--instance-type=ml.g5.xlarge \\
|
|
452
|
+
--hf-token=$HF_TOKEN \\
|
|
453
|
+
--region=us-east-1 \\
|
|
454
|
+
--skip-prompts
|
|
455
|
+
|
|
456
|
+
# TensorRT-LLM with custom instance type
|
|
457
|
+
ml-container-creator my-tensorrt-project \\
|
|
458
|
+
--framework=transformers \\
|
|
459
|
+
--model-name=openai/gpt-oss-20b \\
|
|
460
|
+
--model-server=tensorrt-llm \\
|
|
461
|
+
--instance-type=ml.g6.12xlarge \\
|
|
462
|
+
--skip-prompts
|
|
463
|
+
|
|
464
|
+
# SGLang with Mistral model
|
|
465
|
+
ml-container-creator my-sglang-project \\
|
|
466
|
+
--framework=transformers \\
|
|
467
|
+
--model-name=mistralai/Mistral-7B-Instruct-v0.2 \\
|
|
468
|
+
--model-server=sglang \\
|
|
469
|
+
--instance-type=ml.g5.xlarge \\
|
|
470
|
+
--skip-prompts
|
|
471
|
+
|
|
472
|
+
# XGBoost with FastAPI and custom role
|
|
473
|
+
ml-container-creator my-xgb-project \\
|
|
474
|
+
--framework=xgboost \\
|
|
475
|
+
--model-server=fastapi \\
|
|
476
|
+
--model-format=json \\
|
|
477
|
+
--include-sample \\
|
|
478
|
+
--include-testing \\
|
|
479
|
+
--role-arn=arn:aws:iam::123456789012:role/SageMakerRole \\
|
|
480
|
+
--skip-prompts
|
|
481
|
+
|
|
482
|
+
# CodeBuild deployment target
|
|
483
|
+
ml-container-creator my-codebuild-project \\
|
|
484
|
+
--framework=sklearn \\
|
|
485
|
+
--model-server=flask \\
|
|
486
|
+
--model-format=pkl \\
|
|
487
|
+
--build-target=codebuild \\
|
|
488
|
+
--codebuild-compute-type=BUILD_GENERAL1_MEDIUM \\
|
|
489
|
+
--codebuild-project-name=my-build-project \\
|
|
490
|
+
--skip-prompts
|
|
491
|
+
|
|
492
|
+
# Using configuration file
|
|
493
|
+
ml-container-creator --config=production.json --skip-prompts
|
|
494
|
+
|
|
495
|
+
# With validation options
|
|
496
|
+
ml-container-creator \\
|
|
497
|
+
--framework=transformers \\
|
|
498
|
+
--model-name=meta-llama/Llama-2-7b-chat-hf \\
|
|
499
|
+
--model-server=vllm \\
|
|
500
|
+
--instance-type=ml.g5.xlarge \\
|
|
501
|
+
--validate-env-vars=true \\
|
|
502
|
+
--validate-with-docker=false \\
|
|
503
|
+
--offline=false \\
|
|
504
|
+
--skip-prompts
|
|
505
|
+
`);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Get empty configuration template
|
|
510
|
+
* @private
|
|
511
|
+
*/
|
|
512
|
+
_getEmptyConfig() {
|
|
513
|
+
return {
|
|
514
|
+
'projectName': 'my-ml-project',
|
|
515
|
+
'framework': 'sklearn',
|
|
516
|
+
'modelServer': 'flask',
|
|
517
|
+
'modelFormat': 'pkl',
|
|
518
|
+
'includeSampleModel': false,
|
|
519
|
+
'includeTesting': true,
|
|
520
|
+
'testTypes': ['local-model-cli', 'local-model-server', 'hosted-model-endpoint'],
|
|
521
|
+
'buildTarget': 'codebuild',
|
|
522
|
+
'codebuildComputeType': 'BUILD_GENERAL1_MEDIUM',
|
|
523
|
+
'codebuildProjectName': 'my-build-project',
|
|
524
|
+
'instanceType': 'ml.m5.large',
|
|
525
|
+
'awsRegion': 'us-east-1'
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|