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

Add spot in runpod #1119

Merged
merged 5 commits into from
May 6, 2024
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 src/dstack/_internal/core/backends/cudo/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def create_instance(
instance_id=resp_data["id"],
hostname=None,
internal_ip=None,
region=resp_data["vm"]["regionId"],
region=instance_offer.region,
price=instance_offer.price,
ssh_port=22,
username="root",
Expand Down
51 changes: 27 additions & 24 deletions src/dstack/_internal/core/backends/runpod/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ def create_pod(
docker_args: str = "",
ports: Optional[str] = None,
volume_mount_path: str = "/runpod-volume",
env: Optional[dict] = None,
env: Optional[Dict[str, Any]] = None,
template_id: Optional[str] = None,
network_volume_id: Optional[str] = None,
allowed_cuda_versions: Optional[list] = None,
allowed_cuda_versions: Optional[List[str]] = None,
bid_per_gpu: Optional[float] = None,
) -> Dict:
resp = self._make_request(
{
Expand All @@ -72,11 +73,12 @@ def create_pod(
template_id,
network_volume_id,
allowed_cuda_versions,
bid_per_gpu,
)
}
)
data = resp.json()
return data["data"]["podFindAndDeployOnDemand"]
data = resp.json()["data"]
return data["podRentInterruptable"] if bid_per_gpu else data["podFindAndDeployOnDemand"]

def get_pod(self, pod_id: str) -> Dict:
resp = self._make_request({"query": generate_pod_query(pod_id)})
Expand Down Expand Up @@ -134,7 +136,7 @@ def wait_for_instance(self, instance_id) -> Optional[Dict]:
"""


def generate_pod_query(pod_id) -> str:
def generate_pod_query(pod_id: str) -> str:
"""
Generate a query for a specific GPU type
"""
Expand Down Expand Up @@ -196,13 +198,14 @@ def generate_pod_deployment_mutation(
docker_args=None,
ports=None,
volume_mount_path=None,
env: dict = None,
env: Optional[Dict[str, Any]] = None,
template_id=None,
network_volume_id=None,
allowed_cuda_versions: Optional[List[str]] = None,
bid_per_gpu: Optional[float] = None,
) -> str:
"""
Generates a mutation to deploy a pod on demand.
Generates a mutation to deploy pod.
"""
input_fields = []

Expand All @@ -223,6 +226,8 @@ def generate_pod_deployment_mutation(
input_fields.append("supportPublicIp: false")

# ------------------------------ Optional Fields ----------------------------- #
if bid_per_gpu is not None:
input_fields.append(f"bidPerGpu: {bid_per_gpu}")
if data_center_id is not None:
input_fields.append(f'dataCenterId: "{data_center_id}"')
if country_code is not None:
Expand Down Expand Up @@ -261,27 +266,25 @@ def generate_pod_deployment_mutation(
)
input_fields.append(f"allowedCudaVersions: [{allowed_cuda_versions_string}]")

pod_deploy = "podFindAndDeployOnDemand" if bid_per_gpu is None else "podRentInterruptable"
# Format input fields
input_string = ", ".join(input_fields)

return f"""
mutation {{
podFindAndDeployOnDemand(
input: {{
{input_string}
}}
) {{
id
desiredStatus
imageName
env
machineId
machine {{
podHostId
mutation {{
{pod_deploy}(
input: {{
{input_string}
}}
) {{
id
lastStatusChange
imageName
machine {{
podHostId
}}
}}
}}
}}
}}
"""
"""


def generate_pod_terminate_mutation(pod_id: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion src/dstack/_internal/core/backends/runpod/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def run_job(
support_public_ip=True,
docker_args=get_docker_args(authorized_keys),
ports="10022/tcp",
bid_per_gpu=instance_offer.price if instance_offer.instance.resources.spot else None,
)
instance_id = resp["id"]
return JobProvisioningData(
Expand Down Expand Up @@ -122,7 +123,7 @@ def update_provisioning_data(
provisioning_data.ssh_port = port["publicPort"]


def get_docker_args(authorized_keys):
def get_docker_args(authorized_keys: List[str]) -> str:
commands = get_docker_commands(authorized_keys, False)
command = " && ".join(commands)
command_escaped = command.replace('"', '\\"')
Expand Down
Loading