Skip to content

Commit 485be03

Browse files
committed
alias inferentia to trainium like @Batch does
1 parent 93b108a commit 485be03

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

metaflow/plugins/kubernetes/kubernetes_decorator.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class KubernetesDecorator(StepDecorator):
102102
by the AWS Neuron device plugin -- same resource regardless of whether
103103
the underlying chip is Trainium or Inferentia, since they share the
104104
device-plugin / AMI / runtime stack.
105+
inferentia : int, optional, default None
106+
Alias for `trainium`. Use only one of the two. Provided for API
107+
consistency with `@batch(inferentia=...)`.
105108
efa : int, optional, default None
106109
Number of AWS Elastic Fabric Adapter network interfaces required for
107110
this step. Maps to the `vpc.amazonaws.com/efa` Kubernetes resource
@@ -164,6 +167,7 @@ class KubernetesDecorator(StepDecorator):
164167
"gpu": None, # value of 0 implies that the scheduled node should not have GPUs
165168
"gpu_vendor": None,
166169
"trainium": None, # number of AWS Trainium/Inferentia Neuron devices
170+
"inferentia": None, # alias for trainium; both map to aws.amazon.com/neuron
167171
"efa": None, # number of Elastic Fabric Adapter network interfaces
168172
"tolerations": None, # e.g., [{"key": "arch", "operator": "Equal", "value": "amd"},
169173
# {"key": "foo", "operator": "Equal", "value": "bar"}]
@@ -395,6 +399,23 @@ def step_init(self, flow, graph, step, decos, environment, flow_datastore, logge
395399
max(float(my_val or 0), float(v or 0))
396400
)
397401

402+
# Alias inferentia to trainium and check that both are not in use.
403+
# `trainium` is canonical on @kubernetes (the underlying Neuron device
404+
# plugin advertises a single `aws.amazon.com/neuron` resource for both
405+
# chip families). `inferentia` is provided for API consistency with
406+
# `@batch(inferentia=...)` -- it collapses into `trainium` and is
407+
# popped from the wire format before any runtime translation.
408+
if (
409+
self.attributes["inferentia"] is not None
410+
and self.attributes["trainium"] is not None
411+
):
412+
raise KubernetesException(
413+
"only specify a value for 'inferentia' or 'trainium', not both."
414+
)
415+
if self.attributes["inferentia"] is not None:
416+
self.attributes["trainium"] = self.attributes["inferentia"]
417+
self.attributes.pop("inferentia", None)
418+
398419
# Validate mutually exclusive: gpu and trainium cannot both be set.
399420
if (
400421
self.attributes["trainium"] is not None

0 commit comments

Comments
 (0)