Skip to content

Commit

Permalink
Features/rent gpu query (#137)
Browse files Browse the repository at this point in the history
* added gpu model in query for rent gpu form

* added new gpu models endpoint

* load gpu models in rent-gpu form

* add interface to gpu models api

* add memory + interface to the gpu form control

* added multiple gpu models

* generate sdl with ram + interface

* fix sdl import + remove provider attributes schema

* clearable value for memory + interface + bug fixes

* fix sdl builder

* fix new deployment sdl builder for gpus

* pr fixes
  • Loading branch information
baktun14 authored Mar 28, 2024
1 parent 9f3723d commit a977008
Show file tree
Hide file tree
Showing 26 changed files with 624 additions and 355 deletions.
3 changes: 2 additions & 1 deletion api/src/caching/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ export const cacheKeys = {
getSandboxNodes: "getSandboxNodes",
getMainnetVersion: "getMainnetVersion",
getTestnetVersion: "getTestnetVersion",
getSandboxVersion: "getSandboxVersion"
getSandboxVersion: "getSandboxVersion",
getGpuModels: "getGpuModels",
};
50 changes: 50 additions & 0 deletions api/src/routers/internalRouter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Block } from "@shared/dbSchemas";
import { Lease, Provider } from "@shared/dbSchemas/akash";
import { cacheKeys, cacheResponse } from "@src/caching/helpers";
import { chainDb } from "@src/db/dbConnection";
import { GpuVendor, ProviderConfigGpusType } from "@src/types/gpu";
import { isValidBech32Address } from "@src/utils/addresses";
import { getGpuInterface } from "@src/utils/gpu";
import { round } from "@src/utils/math";
import axios from "axios";
import { differenceInSeconds } from "date-fns";
import { Hono } from "hono";
import * as semver from "semver";
Expand Down Expand Up @@ -232,3 +236,49 @@ internalRouter.get("leases-duration/:owner", async (c) => {
leases
});
});

internalRouter.get("gpu-models", async (c) => {
const response = await cacheResponse(60 * 2, cacheKeys.getGpuModels, async () => {
const res = await axios.get<ProviderConfigGpusType>("https://raw.githubusercontent.com/akash-network/provider-configs/main/devices/pcie/gpus.json");
return res.data;
});

const gpuModels: GpuVendor[] = [];

// Loop over vendors
for (const [, vendorValue] of Object.entries(response)) {
const vendor: GpuVendor = {
name: vendorValue.name,
models: []
};

// Loop over models
for (const [, modelValue] of Object.entries(vendorValue.devices)) {
const _modelValue = modelValue as {
name: string;
memory_size: string;
interface: string;
};
const existingModel = vendor.models.find((x) => x.name === _modelValue.name);

if (existingModel) {
if (!existingModel.memory.includes(_modelValue.memory_size)) {
existingModel.memory.push(_modelValue.memory_size);
}
if (!existingModel.interface.includes(getGpuInterface(_modelValue.interface))) {
existingModel.interface.push(getGpuInterface(_modelValue.interface));
}
} else {
vendor.models.push({
name: _modelValue.name,
memory: [_modelValue.memory_size],
interface: [getGpuInterface(_modelValue.interface)]
});
}
}

gpuModels.push(vendor);
}

return c.json(gpuModels);
});
2 changes: 1 addition & 1 deletion api/src/services/db/providerDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function getProviderRegions() {
include: [{ model: ProviderAttribute, attributes: ["value"], where: { key: "location-region" } }]
});

console.log(JSON.stringify(providers, null, 2));
// console.log(JSON.stringify(providers, null, 2));
const result = regions.map((region) => {
const filteredProviders = providers.filter((p) => p.providerAttributes.some((attr) => attr.value === region.key)).map((x) => x.owner);
return { ...region, providers: filteredProviders };
Expand Down
23 changes: 23 additions & 0 deletions api/src/types/gpu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export interface GpuVendor {
name: string;
models: GpuModel[];
}

export interface GpuModel {
name: string;
memory: string[];
interface: string[];
}

export type ProviderConfigGpusType = {
[key: string]: {
name: string;
devices: {
[key: string]: {
name: string;
memory_size: string;
interface: string;
};
};
};
};
4 changes: 4 additions & 0 deletions api/src/utils/gpu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function getGpuInterface(gpuInterface: string) {
const _formatted = gpuInterface.toLowerCase();
return _formatted.startsWith("sxm") ? "sxm" : _formatted;
}
14 changes: 7 additions & 7 deletions deploy-web/package-lock.json

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

2 changes: 1 addition & 1 deletion deploy-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"postinstall": "patch-package"
},
"dependencies": {
"@akashnetwork/akashjs": "0.5.10",
"@akashnetwork/akashjs": "0.5.11",
"@auth0/nextjs-auth0": "^3.1.0",
"@cosmjs/encoding": "^0.29.5",
"@cosmjs/stargate": "^0.29.5",
Expand Down
9 changes: 5 additions & 4 deletions deploy-web/src/components/newDeploymentWizard/SdlBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { nanoid } from "nanoid";
import { generateSdl } from "@src/utils/sdl/sdlGenerator";
import { Alert, Box, Button, CircularProgress } from "@mui/material";
import { SimpleServiceFormControl } from "../sdl/SimpleServiceFormControl";
import { useProviderAttributesSchema } from "@src/queries/useProvidersQuery";
import { importSimpleSdl } from "@src/utils/sdl/sdlImport";
import { useGpuModels } from "@src/queries/useGpuQuery";

interface Props {
sdlString: string;
Expand Down Expand Up @@ -38,7 +38,7 @@ export const SdlBuilder = React.forwardRef<SdlBuilderRefType, Props>(({ sdlStrin
keyName: "id"
});
const { services: _services } = watch();
const { data: providerAttributesSchema } = useProviderAttributesSchema();
const { data: gpuModels } = useGpuModels();
const [serviceCollapsed, setServiceCollapsed] = useState([]);

React.useImperativeHandle(ref, () => ({
Expand Down Expand Up @@ -78,7 +78,7 @@ export const SdlBuilder = React.forwardRef<SdlBuilderRefType, Props>(({ sdlStrin
try {
if (!yamlStr) return [];

const services = importSimpleSdl(yamlStr, providerAttributesSchema);
const services = importSimpleSdl(yamlStr);

setError(null);

Expand Down Expand Up @@ -117,7 +117,8 @@ export const SdlBuilder = React.forwardRef<SdlBuilderRefType, Props>(({ sdlStrin
key={service.id}
serviceIndex={serviceIndex}
_services={_services}
providerAttributesSchema={providerAttributesSchema}
gpuModels={gpuModels}
setValue={setValue}
control={control}
trigger={trigger}
onRemoveService={onRemoveService}
Expand Down
4 changes: 1 addition & 3 deletions deploy-web/src/components/sdl/AdvancedConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import { ProviderAttributesSchema } from "@src/types/providerAttributes";
import { PersistentStorage } from "./PersistentStorage";

type Props = {
providerAttributesSchema: ProviderAttributesSchema;
currentService: Service;
control: Control<RentGpusFormValues, any>;
children?: ReactNode;
};

export const AdvancedConfig: React.FunctionComponent<Props> = ({ control, currentService, providerAttributesSchema }) => {
export const AdvancedConfig: React.FunctionComponent<Props> = ({ control, currentService }) => {
const theme = useTheme();
const [expanded, setIsAdvancedOpen] = useState(false);
const [isEditingCommands, setIsEditingCommands] = useState(false);
Expand All @@ -42,7 +41,6 @@ export const AdvancedConfig: React.FunctionComponent<Props> = ({ control, curren
serviceIndex={0}
expose={currentService.expose}
services={[currentService]}
providerAttributesSchema={providerAttributesSchema}
/>
)}

Expand Down
12 changes: 2 additions & 10 deletions deploy-web/src/components/sdl/ExposeFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { CustomTooltip } from "../shared/CustomTooltip";
import InfoIcon from "@mui/icons-material/Info";
import { endpointNameValidationRegex } from "@src/utils/deploymentData/v1beta3";
import { HttpOptionsFormControl } from "./HttpOptionsFormControl";
import { ProviderAttributesSchema } from "@src/types/providerAttributes";

type Props = {
serviceIndex: number;
Expand All @@ -22,10 +21,9 @@ type Props = {
children?: ReactNode;
services: Service[];
expose: Expose[];
providerAttributesSchema: ProviderAttributesSchema;
};

export const ExposeFormModal: React.FunctionComponent<Props> = ({ control, serviceIndex, onClose, expose: _expose, services, providerAttributesSchema }) => {
export const ExposeFormModal: React.FunctionComponent<Props> = ({ control, serviceIndex, onClose, expose: _expose, services }) => {
const acceptRef = useRef<AcceptRefType>();
const toRef = useRef<ToRefType>();
const {
Expand Down Expand Up @@ -308,13 +306,7 @@ export const ExposeFormModal: React.FunctionComponent<Props> = ({ control, servi
</Box>

<Box sx={{ marginTop: "1rem" }}>
<HttpOptionsFormControl
control={control}
serviceIndex={serviceIndex}
exposeIndex={expIndex}
services={services}
providerAttributesSchema={providerAttributesSchema}
/>
<HttpOptionsFormControl control={control} serviceIndex={serviceIndex} exposeIndex={expIndex} services={services} />
</Box>
</Box>

Expand Down
94 changes: 0 additions & 94 deletions deploy-web/src/components/sdl/FormSelect.tsx

This file was deleted.

Loading

0 comments on commit a977008

Please sign in to comment.