Skip to content

Commit

Permalink
Enable GPU for local runner (#377)
Browse files Browse the repository at this point in the history
PR that adds GPU resource for the local runner when specified in the
componentOP

based on: 
https://docs.docker.com/compose/gpu-support/
  • Loading branch information
PhilippeMoussalli authored Aug 23, 2023
1 parent 50f3a97 commit 2cbecac
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/fondant/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def ignore_aliases(self, data):
return True

with open(output_path, "w") as outfile:
yaml.dump(spec, outfile, Dumper=NoAliasDumper)
yaml.dump(spec, outfile, Dumper=NoAliasDumper, default_flow_style=False)

logger.info(f"Successfully compiled to {output_path}")

Expand Down Expand Up @@ -176,6 +176,21 @@ def _generate_spec(
"volumes": volumes,
}

if component_op.number_of_gpus is not None:
services[component_name]["deploy"] = {
"resources": {
"reservations": {
"devices": [
{
"driver": "nvidia",
"count": component_op.number_of_gpus,
"capabilities": ["gpu"],
},
],
},
},
}

if component_op.dockerfile_path is not None:
logger.info(
f"Found Dockerfile for {component_name}, adding build step.",
Expand All @@ -186,6 +201,7 @@ def _generate_spec(
}
else:
services[component_name]["image"] = component_op.component_spec.image

return {
"name": pipeline.name,
"version": "3.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ services:
{"type": "binary"}}}, "captions": {"fields": {"data": {"type": "string"}}}},
"args": {"storage_args": {"description": "Storage arguments", "type": "str"}}}'
depends_on: {}
deploy:
resources:
reservations:
devices:
- capabilities:
- gpu
count: 1
driver: nvidia
volumes: []
second_component:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ spec:
- --output_manifest_path
- /tmp/outputs/output_manifest_path/data
image: example_component:latest
resources:
limits:
nvidia.com/gpu: 1
inputs:
artifacts:
- name: input_manifest_path
Expand Down
1 change: 1 addition & 0 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Path(COMPONENTS_PATH / "example_1" / "first_component"),
arguments={"storage_args": "a dummy string arg"},
input_partition_rows="disable",
number_of_gpus=1,
),
ComponentOp(
Path(COMPONENTS_PATH / "example_1" / "second_component"),
Expand Down

0 comments on commit 2cbecac

Please sign in to comment.