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

Added support for google TPU #2143

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
created a separated attribute for TPU
kulikovv committed Dec 30, 2024
commit 44dc3b3bcb47b0e828ffc77a7def92745214d214
39 changes: 28 additions & 11 deletions metaflow/plugins/kubernetes/kubernetes_decorator.py
Original file line number Diff line number Diff line change
@@ -83,6 +83,11 @@ class KubernetesDecorator(StepDecorator):
the scheduled node should not have GPUs.
gpu_vendor : str, default KUBERNETES_GPU_VENDOR
The vendor of the GPUs to be used for this step.
tpu : int, optional, default None
Number of TPUs required for this step. A value of zero implies that
the scheduled node should not have TPUs.
tpu_vendor : str, default KUBERNETES_TPU_VENDOR
The vendor of the TPUs to be used for this step.
tolerations : List[str], default []
The default is extracted from METAFLOW_KUBERNETES_TOLERATIONS.
Kubernetes tolerations to use when launching pod in Kubernetes.
@@ -124,6 +129,8 @@ class KubernetesDecorator(StepDecorator):
"namespace": None,
"gpu": None, # value of 0 implies that the scheduled node should not have GPUs
"gpu_vendor": None,
"tpu": None, # value of 0 implies that the scheduled node should not have TPUs
"tpu_vendor": None,
"tolerations": None, # e.g., [{"key": "arch", "operator": "Equal", "value": "amd"},
# {"key": "foo", "operator": "Equal", "value": "bar"}]
"use_tmpfs": None,
@@ -286,9 +293,9 @@ def step_init(self, flow, graph, step, decos, environment, flow_datastore, logge
for deco in decos:
if isinstance(deco, ResourcesDecorator):
for k, v in deco.attributes.items():
# If GPU count is specified, explicitly set it in self.attributes.
if k == "gpu" and v != None:
self.attributes["gpu"] = v
# If GPU/TPU count is specified, explicitly set it in self.attributes.
if k in ("gpu","tpu") and v != None:
self.attributes[k] = v

if k in self.attributes:
if self.defaults[k] is None:
@@ -309,6 +316,14 @@ def step_init(self, flow, graph, step, decos, environment, flow_datastore, logge
self.attributes["gpu_vendor"], step=step
)
)

# Check TPU vendor.
if self.attributes["tpu_vendor"].lower() not in ("google"):
raise KubernetesException(
"TPU vendor *{}* for step *{step}* is not currently supported.".format(
self.attributes["tpu_vendor"], step=step
)
)

# CPU, Disk, and Memory values should be greater than 0.
for attr in ["cpu", "disk", "memory"]:
@@ -322,15 +337,17 @@ def step_init(self, flow, graph, step, decos, environment, flow_datastore, logge
)
)

if self.attributes["gpu"] is not None and not (
isinstance(self.attributes["gpu"], (int, unicode, basestring))
and float(self.attributes["gpu"]).is_integer()
):
raise KubernetesException(
"Invalid GPU value *{}* for step *{step}*; it should be an integer".format(
self.attributes["gpu"], step=step
for accelerator_type in ("gpu", "tpu"):
if self.attributes[accelerator_type] is not None and not (
isinstance(self.attributes[accelerator_type], (int, unicode, basestring))
and float(self.attributes[accelerator_type]).is_integer()
):
raise KubernetesException(
"Invalid {accelerator_type} value *{number}* for step *{step}*; it should be an integer".format(
accelerator_type=accelerator_type.toUpper(), number=self.attributes[accelerator_type], step=step
)
)
)


if self.attributes["tmpfs_size"]:
if not (
2 changes: 1 addition & 1 deletion metaflow/plugins/kubernetes/kubernetes_job.py
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ def create_gpu_vendor_string(vendor):
device_type = "gpu"
if vendor == "google":
device_type = "tpu"
return f"{vendor}.com/{device_type}".lower()
return "{vendor}.com/{device_type}".format(vendor=vendor, device_type=device_type).lower()


class KubernetesJob(object):