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

Enable multi-gpu containers #442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions pkg/abstractions/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func (cs *CmdContainerService) ExecuteCommand(in *pb.CommandExecutionRequest, st

env = append(secrets, env...)

gpuCount := 0
if stubConfig.Runtime.Gpu != "" {
gpuCount := stubConfig.Runtime.GpuCount
if stubConfig.Runtime.Gpu != "" && gpuCount == 0 {
gpuCount = 1
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/abstractions/endpoint/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (i *endpointInstance) startContainers(containersToRun int) error {

env = append(secrets, env...)

gpuCount := 0
if i.StubConfig.Runtime.Gpu != "" {
gpuCount := i.StubConfig.Runtime.GpuCount
if i.StubConfig.Runtime.Gpu != "" && gpuCount == 0 {
gpuCount = 1
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/abstractions/function/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func (t *FunctionTask) run(ctx context.Context, stub *types.StubWithRelated) err
return err
}

gpuCount := 0
if stubConfig.Runtime.Gpu != "" {
gpuCount := stubConfig.Runtime.GpuCount
if stubConfig.Runtime.Gpu != "" && gpuCount == 0 {
gpuCount = 1
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/abstractions/taskqueue/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (i *taskQueueInstance) startContainers(containersToRun int) error {

env = append(secrets, env...)

gpuCount := 0
if i.StubConfig.Runtime.Gpu != "" {
gpuCount := i.StubConfig.Runtime.GpuCount
if i.StubConfig.Runtime.Gpu != "" && gpuCount == 0 {
gpuCount = 1
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/gateway/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ service GatewayService {
// Deployments
rpc ListDeployments(ListDeploymentsRequest) returns (ListDeploymentsResponse);
rpc StopDeployment(StopDeploymentRequest) returns (StopDeploymentResponse);
rpc DeleteDeployment(DeleteDeploymentRequest) returns (DeleteDeploymentResponse);
rpc DeleteDeployment(DeleteDeploymentRequest)
returns (DeleteDeploymentResponse);

// Pools
rpc ListPools(ListPoolsRequest) returns (ListPoolsResponse);
Expand Down Expand Up @@ -222,6 +223,7 @@ message GetOrCreateStubRequest {
bool authorized = 20;
repeated SecretVar secrets = 21;
Autoscaler autoscaler = 22;
uint32 gpu_count = 23;
}

message GetOrCreateStubResponse {
Expand Down
13 changes: 9 additions & 4 deletions pkg/gateway/services/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ func (gws *GatewayService) GetOrCreateStub(ctx context.Context, in *pb.GetOrCrea
autoscaler.TasksPerContainer = uint(in.Autoscaler.TasksPerContainer)
}

if in.Gpu != "" && in.GpuCount == 0 {
in.GpuCount = uint32(1)
}

stubConfig := types.StubConfigV1{
Runtime: types.Runtime{
Cpu: in.Cpu,
Gpu: types.GpuType(in.Gpu),
Memory: in.Memory,
ImageId: in.ImageId,
Cpu: in.Cpu,
Gpu: types.GpuType(in.Gpu),
Memory: in.Memory,
ImageId: in.ImageId,
GpuCount: in.GpuCount,
},
Handler: in.Handler,
OnStart: in.OnStart,
Expand Down
9 changes: 5 additions & 4 deletions pkg/types/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,11 @@ type Image struct {
}

type Runtime struct {
Cpu int64 `json:"cpu"`
Gpu GpuType `json:"gpu"`
Memory int64 `json:"memory"`
ImageId string `json:"image_id"`
Cpu int64 `json:"cpu"`
Gpu GpuType `json:"gpu"`
GpuCount uint32 `json:"gpu_count"`
Memory int64 `json:"memory"`
ImageId string `json:"image_id"`
}

type GpuType string
Expand Down
648 changes: 329 additions & 319 deletions proto/gateway.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions sdk/src/beta9/abstractions/base/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(
cpu: Union[int, float, str] = 1.0,
memory: Union[int, str] = 128,
gpu: GpuTypeAlias = GpuType.NoGPU,
gpu_count: int = 0,
image: Image = Image(),
workers: int = 1,
keep_warm_seconds: float = 10.0,
Expand Down Expand Up @@ -81,6 +82,7 @@ def __init__(
self.cpu = cpu
self.memory = self._parse_memory(memory) if isinstance(memory, str) else memory
self.gpu = gpu
self.gpu_count = gpu_count
self.volumes = volumes or []
self.secrets = [SecretVar(name=s) for s in (secrets or [])]
self.workers = workers
Expand All @@ -90,6 +92,9 @@ def __init__(
self.timeout = timeout
self.autoscaler = autoscaler

if self.gpu != "" and self.gpu_count == 0:
self.gpu_count = 1

if on_start is not None:
self._map_callable_to_attr(attr="on_start", func=on_start)

Expand Down Expand Up @@ -320,6 +325,7 @@ def prepare_runtime(
cpu=self.cpu,
memory=self.memory,
gpu=self.gpu,
gpu_count=self.gpu_count,
handler=self.handler,
on_start=self.on_start,
callback_url=self.callback_url,
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/beta9/abstractions/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
cpu: Union[int, float, str] = 1.0,
memory: Union[int, str] = 128,
gpu: GpuTypeAlias = GpuType.NoGPU,
gpu_count: int = 0,
image: Image = Image(),
volumes: Optional[List[Volume]] = None,
secrets: Optional[List[str]] = None,
Expand All @@ -68,6 +69,7 @@ def __init__(
cpu=cpu,
memory=memory,
gpu=gpu,
gpu_count=gpu_count,
image=image,
volumes=volumes,
secrets=secrets,
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/beta9/abstractions/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(
cpu: Union[int, float, str] = 1.0,
memory: Union[int, str] = 128,
gpu: GpuTypeAlias = GpuType.NoGPU,
gpu_count: int = 0,
image: Image = Image(),
timeout: int = 180,
workers: int = 1,
Expand All @@ -117,6 +118,7 @@ def __init__(
cpu=cpu,
memory=memory,
gpu=gpu,
gpu_count=gpu_count,
image=image,
workers=workers,
timeout=timeout,
Expand Down Expand Up @@ -150,6 +152,7 @@ def __init__(
cpu: Union[int, float, str] = 1.0,
memory: Union[int, str] = 128,
gpu: GpuTypeAlias = GpuType.NoGPU,
gpu_count: int = 0,
image: Image = Image(),
timeout: int = 180,
workers: int = 1,
Expand All @@ -167,6 +170,7 @@ def __init__(
cpu,
memory,
gpu,
gpu_count,
image,
timeout,
workers,
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/beta9/abstractions/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(
cpu: Union[int, float, str] = 1.0,
memory: Union[int, str] = 128,
gpu: GpuTypeAlias = GpuType.NoGPU,
gpu_count: int = 0,
image: Image = Image(),
timeout: int = 3600,
retries: int = 3,
Expand All @@ -88,6 +89,7 @@ def __init__(
cpu=cpu,
memory=memory,
gpu=gpu,
gpu_count=gpu_count,
image=image,
timeout=timeout,
retries=retries,
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/beta9/abstractions/taskqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(
cpu: Union[int, float, str] = 1.0,
memory: Union[int, str] = 128,
gpu: GpuTypeAlias = GpuType.NoGPU,
gpu_count: int = 0,
image: Image = Image(),
timeout: int = 3600,
retries: int = 3,
Expand All @@ -114,6 +115,7 @@ def __init__(
cpu=cpu,
memory=memory,
gpu=gpu,
gpu_count=gpu_count,
image=image,
workers=workers,
timeout=timeout,
Expand Down
1 change: 1 addition & 0 deletions sdk/src/beta9/clients/gateway/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading