* feat(sagemaker): support GPU-backed training jobs ResourceConfig.InstanceType had no effect on the container Floci launched, so a training job asking for ml.g5.xlarge ran on CPU. This maps the accelerator half of an instance type onto a real device request, using the container GPU primitive added in #3789. On AWS the instance type *is* the hardware, so nothing is configurable. Floci has one host with fixed cards, so serving a GPU instance type means substituting a local device, and which devices may be lent out is a local decision. The two halves are split accordingly: - How many accelerators an ml.* type carries is a property of AWS, so it ships as data in sagemaker/instance-type-catalog.yaml, mirroring how Ec2InstanceTypeCatalog already carries vcpu and memory for EC2 types. It is kept separate from that catalog because ml.* is its own namespace and must never appear in DescribeInstanceTypes. - Which of this machine's devices may be used is configuration, under floci.services.sagemaker.gpu: enabled, mode and devices. Nothing changes unless enabled is set. It defaults to false, so existing deployments keep launching CPU-only containers, including for GPU instance types. mode exists because daemons disagree on the wire form. It defaults to cdi: Podman resolves only CDI and accepts a count request while attaching no device (containers/podman#22645), so preferring CDI turns a misconfiguration into a refused start rather than a job that quietly trains on CPU. That principle drives the failure cases too: an unlisted GPU-family type, too few allowed devices, an explicit mode with no devices, and InstanceCount above one all fail with a FailureReason instead of falling back to CPU. A job that reports Completed after training on the wrong hardware leaves an artifact that looks legitimate, which is worse than an error. Only the accelerator is substituted. An instance type also implies vCPU and memory, which this does not emulate, consistent with the rest of the codebase: EC2 instance types are metadata for DescribeInstanceTypes and never size a container, RDS records DBInstanceClass without acting on it, and Lambda, ECS and Batch apply limits only where an API supplies an explicit number. Endpoint hosting is unchanged and still CPU-only; the resolver is a separate bean so it can be reused there in a follow-up. * test(sagemaker): cover the GPU refusal paths and the hardware path The GPU feature shipped with unit coverage on the resolver only, so nothing exercised it through CreateTrainingJob. These add both halves. SageMakerGpuIntegrationTest runs everywhere. Every path that refuses a request raises inside SageMakerGpuResolver, before the runner asks the daemon for anything, and the removeIfExists above it already swallows a missing daemon, so an unlisted GPU family, InstanceCount above one, and cdi mode with no configured devices all reach their verdict on a plain runner. A fourth case pins the contract that enabling the feature leaves CPU instance types alone. SageMakerGpuDockerIntegrationTest is opt-in behind -Dgpu.integration.enabled, matching ContainerGpuDockerIntegrationTest, because it needs hardware no CI runner has. Verified against an RTX 5060 Ti through Podman 5.8.2: the container saw exactly the device named in gpu.devices and not the host's other card. The assertion is the container's exit code. nvidia-smi output is redirected rather than piped: a pipeline exits with the status of its last command, so 'nvidia-smi -L | tee' reports success even when nvidia-smi cannot reach the driver, which would be this test passing on a CPU container. * fix(sagemaker): package the instance type catalog in the native image SageMakerInstanceTypeCatalog reads sagemaker/instance-type-catalog.yaml through a constant, which Quarkus's static resource analysis cannot follow, and no glob under quarkus.native.resources.includes matched it. The file was therefore left out of the native image, so enabling floci.services.sagemaker.gpu.enabled there would have failed every training job at catalog load with 'Missing catalog resource sagemaker/instance-type-catalog.yaml'. Ec2InstanceTypeCatalog reads its own catalog the same way and ec2/*.yaml was already listed for exactly this reason. Nothing caught it: JVM tests resolve the file from src/main/resources, and the hardware verification ran a JVM-mode image, so the gap existed only in the artifact neither exercised. NativeImageResourceIncludesTest closes that gap the way NativeImageRuntimeInitializationTest closes the Random-in-the-image-heap one, by moving a native-only failure into ordinary CI. It pairs each resource-path constant passed to getResourceAsStream with the includes globs and fails when none matches, skipping the IAM catalog that application.yml already documents as build-time only. * refactor(sagemaker): match EC2's case handling for instance types isAcceleratorFamily folded case while gpuCount did not, so ML.G5.XLARGE was answered as a GPU family and then reported as missing from the catalog, pointing the caller at the wrong fix. Ec2InstanceTypeCatalog is the precedent and normalizes in neither position: find() looks the type up exactly and familyOf() splits on the first dot without folding. AWS instance types are exact tokens. The repo folds case where AWS defines a value as case-insensitive, such as ACM domain names, regions and content types, which an instance type is not. Dropping the fold rather than adding one to gpuCount keeps both halves agreeing and keeps the pair behaving like EC2's. Also drops the @DisplayName from SageMakerGpuResolverTest. The suite does not use them anywhere else; the method name carries the intent. * docs(sagemaker): clarify GPU training device reuse
7.3 KiB
Amazon SageMaker
Floci emulates SageMaker control-plane APIs and runs real Docker containers for local training jobs and hosted endpoints. Containers use the SageMaker /opt/ml contract rather than mocks.
Supported operations
| Area | Operations |
|---|---|
| Models | CreateModel, DescribeModel, DeleteModel, ListModels |
| Endpoint configs | CreateEndpointConfig, DescribeEndpointConfig, DeleteEndpointConfig, ListEndpointConfigs |
| Endpoints | CreateEndpoint, DescribeEndpoint, UpdateEndpoint, DeleteEndpoint, ListEndpoints |
| Training | CreateTrainingJob, DescribeTrainingJob, ListTrainingJobs, StopTrainingJob |
| Tags | AddTags, ListTags, DeleteTags |
| Runtime | POST /endpoints/{EndpointName}/invocations |
Supported Actions
| Action | Description |
|---|---|
CreateModel |
Registers a model from PrimaryContainer or Containers; rejects an empty Containers array rather than dereferencing it. |
DescribeModel |
Returns a model by name, scoped to the calling region. |
DeleteModel |
Deletes a model by name, scoped to the calling region. |
ListModels |
Lists models for the calling region; supports NameContains, MaxResults (1-100), and NextToken pagination. |
CreateEndpointConfig |
Creates an endpoint configuration; every ProductionVariants[].ModelName must already exist. |
DescribeEndpointConfig |
Returns an endpoint configuration by name, scoped to the calling region. |
DeleteEndpointConfig |
Deletes an endpoint configuration by name, scoped to the calling region. |
ListEndpointConfigs |
Lists endpoint configurations for the calling region; supports MaxResults and NextToken. |
CreateEndpoint |
Starts hosting the configured model image asynchronously; the endpoint is Creating until the container passes its /ping check. |
DescribeEndpoint |
Returns an endpoint's status, scoped to the calling region. |
DeleteEndpoint |
Stops and removes the endpoint's container; a start still in flight for this endpoint discards its result instead of resurrecting the deleted record. |
ListEndpoints |
Lists endpoints for the calling region; supports MaxResults and NextToken. |
UpdateEndpoint |
Swaps an endpoint to a new endpoint configuration, restarting its container; a superseded in-flight start discards its result. |
CreateTrainingJob |
Runs AlgorithmSpecification.TrainingImage asynchronously against the /opt/ml contract and uploads the resulting model artifacts to S3. |
DescribeTrainingJob |
Returns a training job's status, scoped to the calling region. |
ListTrainingJobs |
Lists training jobs for the calling region; supports NameContains, StatusEquals, MaxResults, and NextToken. |
StopTrainingJob |
Stops a training job that is InProgress or Stopping; a no-op against a job already in a terminal state. |
AddTags |
Adds tags to a model, endpoint config, endpoint, or training job identified by ARN. |
ListTags |
Lists tags for a model, endpoint config, endpoint, or training job identified by ARN. |
DeleteTags |
Removes tags by key from a model, endpoint config, endpoint, or training job identified by ARN. |
Training contract
CreateTrainingJob starts AlgorithmSpecification.TrainingImage with command train unless ContainerEntrypoint/ContainerArguments are supplied. Floci writes SageMaker config files under /opt/ml/input/config, downloads channel data from S3 into /opt/ml/input/data/<channel>, waits for container exit, and uploads /opt/ml/model as model.tar.gz under OutputDataConfig.S3OutputPath/<TrainingJobName>/output/.
GPU-backed training
On AWS, ResourceConfig.InstanceType is the hardware: ml.g5.xlarge provisions a machine that physically has one A10G. Floci has one host with whatever cards it has, so a GPU instance type is served by substituting a local device. That substitution is off by default and the SDK request is unchanged either way.
How many accelerators each ml.* type carries is a property of AWS, so it ships with Floci in sagemaker/instance-type-catalog.yaml. Configuration covers only the local decision of which of this machine's devices may be handed out:
floci:
services:
sagemaker:
gpu:
enabled: true
mode: cdi # cdi | device-ids | count
devices:
- nvidia.com/gpu=GPU-0e1f2a3b
| Setting | Meaning |
|---|---|
enabled |
Off by default. While off, every training container is CPU-only, exactly as before. |
mode |
How the request reaches the daemon. cdi names Container Device Interface devices, device-ids uses daemon device ids, and count asks for a number and lets the daemon choose. |
devices |
The devices Floci may use, for cdi and device-ids. Unset allows none, so a shared machine does not hand over every GPU by default. Ignored by count. |
mode defaults to cdi because daemons differ: Podman resolves only CDI and will accept a count request while attaching no device (containers/podman#22645). Choosing CDI means a misconfiguration fails the container start rather than quietly training on CPU. Use count or device-ids against Docker.
Floci does not reserve configured devices across concurrent training jobs. In cdi and device-ids modes, each job takes the first devices it needs from the allowlist, so two simultaneous one-GPU jobs can target the same local card and contend for memory.
A training job fails with an explanatory FailureReason, rather than running on CPU, when:
- the instance type belongs to a GPU family (
ml.g*,ml.p*,ml.inf*,ml.trn*) that the catalog does not list, so its accelerator count is unknown - fewer devices are allowed than the instance type needs
cdiordevice-idsis selected with nodevicesconfiguredInstanceCountis above one, since Floci runs a job as a single container
Only the accelerator is substituted. An instance type also implies vCPU and memory, which Floci does not emulate for any service: EC2 instance types are metadata for DescribeInstanceTypes and do not size containers, and RDS records DBInstanceClass without acting on it. Resource limits are applied only where an API supplies an explicit number, as Lambda's MemorySize does.
Endpoint hosting
CreateEndpoint starts the model image as a long-lived Docker container with command serve, port 8080, /ping health checks, and /invocations runtime proxying. ModelDataUrl artifacts are downloaded from S3 and placed in /opt/ml/model.
Endpoint containers are CPU-only for now; the gpu settings above apply to training jobs.
Examples
import boto3
sm = boto3.client("sagemaker", endpoint_url="http://localhost:4566", region_name="us-east-1")
sm.create_model(ModelName="m", PrimaryContainer={"Image":"my-image"}, ExecutionRoleArn="arn:aws:iam::000000000000:role/r")
sm.create_endpoint_config(EndpointConfigName="cfg", ProductionVariants=[{"VariantName":"AllTraffic","ModelName":"m","InitialInstanceCount":1,"InstanceType":"ml.t2.medium"}])
sm.create_endpoint(EndpointName="ep", EndpointConfigName="cfg")
aws --endpoint-url=http://localhost:4566 sagemaker list-models