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

Fix TypeError: object of type 'NoneType' has no len() in dstack/_internal/backend/gcp/compute.py:513 #668

Merged
merged 1 commit into from
Aug 21, 2023
Merged
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
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
Loading