Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/compute/cloud/hyperstack/util.ts
Views: 687
import type { PurchaseOption } from "@cocalc/util/compute/cloud/hyperstack/pricing";1import { GPU_SPECS } from "@cocalc/util/compute/gpu-specs";2import { field_cmp } from "@cocalc/util/misc";34// Return list of GPU models that Hyperstack sells along with links to their pages.5// This could just be hardcoded, but instead we compute it from actual pricing data6// that comes from their api, combined with our specs data about GPU's. In the7// longrun this should be more maintainable and dynamic.8export function getModelLinks(priceData) {9const x: { [name: string]: { url?: string; cost: number } } = {};10for (const option of Object.values(priceData.options) as PurchaseOption[]) {11const { cost_per_hour, gpu_count, gpu } = option;12const name = toGPU(gpu);13if (typeof cost_per_hour == "string") {14continue;15}16const cost = cost_per_hour / gpu_count;17if (x[name] != null && x[name].cost <= cost) {18continue;19}20const gpuSpec = GPU_SPECS[name];21if (gpuSpec == null) {22continue;23}24x[name] = { url: gpuSpec?.hyperstack ?? gpuSpec?.datasheet, cost };25}26const models: { name: string; url?: string; cost: number }[] = [];27for (const name in x) {28models.push({ name: name.replace("-PCIe", ""), ...x[name] });29}30models.sort(field_cmp("cost"));31models.reverse();32return models;33}3435export function toGPU(gpu) {36gpu = gpu.replace("G-", "GB-");37if (gpu.endsWith("-sm")) {38return gpu.slice(0, -3);39}40gpu = gpu.replace("-NVLink", "");41gpu = gpu.replace("-k8s", "");42gpu = gpu.replace("-ada", "");43return gpu;44}45464748