Skip to content

Commit

Permalink
- [CLI] Fix TypeError: object of type 'NoneType' has no len() in `d…
Browse files Browse the repository at this point in the history
…stack/_internal/backend/gcp/compute.py:513` (#668)
  • Loading branch information
peterschmidt85 authored Aug 21, 2023
1 parent d8d2141 commit a21a07b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cli/dstack/_internal/backend/gcp/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_supported_instances(self) -> List[InstanceType]:
if row["spot"] == "True": # any instance could be spot
continue
instance_key = row["instance_name"]
gpus = None
gpus = []
if int(row["gpu_count"]) > 0:
instance_key += f'-{row["gpu_count"]}x{row["gpu_name"]}-{row["gpu_memory"]}'
gpus = [
Expand Down
6 changes: 3 additions & 3 deletions cli/dstack/_internal/backend/lambdalabs/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _instance_type_data_to_instance_type(instance_type_data: Dict) -> Optional[I
regions = [r["name"] for r in regions_data]
instance_type_specs = instance_type["specs"]
gpus = _get_instance_type_gpus(instance_type["name"])
if gpus is None:
if len(gpus) == 0:
return None
return InstanceType(
instance_name=instance_type["name"],
Expand All @@ -181,10 +181,10 @@ def _instance_type_data_to_instance_type(instance_type_data: Dict) -> Optional[I
)


def _get_instance_type_gpus(instance_type_name: str) -> Optional[List[Gpu]]:
def _get_instance_type_gpus(instance_type_name: str) -> List[Gpu]:
gpu_data = _INSTANCE_TYPE_TO_GPU_DATA_MAP.get(instance_type_name)
if gpu_data is None:
return None
return []
return [
Gpu(name=gpu_data["name"], memory_mib=gpu_data["memory_mib"])
for _ in range(gpu_data["count"])
Expand Down
8 changes: 6 additions & 2 deletions cli/dstack/_internal/core/runners.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional

from pydantic import BaseModel
from pydantic import BaseModel, validator

from dstack._internal.core.job import Job

Expand All @@ -13,10 +13,14 @@ class Gpu(BaseModel):
class Resources(BaseModel):
cpus: int
memory_mib: int
gpus: Optional[List[Gpu]]
gpus: List[Gpu]
spot: bool
local: bool

@validator("gpus")
def validate_gpus(cls, value):
return value or []


class Runner(BaseModel):
runner_id: str
Expand Down

0 comments on commit a21a07b

Please sign in to comment.