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

Bugfixes/fix provider gpus UI #143

Merged
merged 9 commits into from
Apr 4, 2024
Merged

Bugfixes/fix provider gpus UI #143

merged 9 commits into from
Apr 4, 2024

Conversation

Redm4x
Copy link
Contributor

@Redm4x Redm4x commented Apr 1, 2024

Display gpu models from feature discovery instead of capabilities attributes

  • Return gpu models from feature discovery in providers endpoints
  • Use those model instead of capabilities in provider list/detail pages
  • Added missing indexes to improve performance
CREATE INDEX IF NOT EXISTS provider_snapshot_node_snapshot_id
    ON public."providerSnapshotNode" USING btree
    ("snapshotId" ASC NULLS LAST)
    WITH (deduplicate_items=True)
    TABLESPACE pg_default;
	
CREATE INDEX IF NOT EXISTS provider_snapshot_node_cpu_snapshot_node_id
    ON public."providerSnapshotNodeCPU" USING btree
    ("snapshotNodeId" ASC NULLS LAST)
    WITH (deduplicate_items=True)
    TABLESPACE pg_default;
	
CREATE INDEX IF NOT EXISTS provider_snapshot_node_gpu_snapshot_node_id
    ON public."providerSnapshotNodeGPU" USING btree
    ("snapshotNodeId" ASC NULLS LAST)
    WITH (deduplicate_items=True)
    TABLESPACE pg_default;

@@ -42,6 +42,7 @@ export async function getNetworkCapacity() {
}

export const getProviderList = async () => {
// Fetch provider list with their attributes & auditors
Copy link
Contributor

@ygrishajev ygrishajev Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho this kind of comments don't help much. It's already obvious that providers is a providers list. If it's essential to emphasise it's got attributes and auditors (is it?) it can be named accordingly. e.g. providersWithAttrsAndAuditors. It would also help understanding code better further if it's important.

const gpuModels = (nodes || [])
.flatMap((x) => x.gpus)
.map((x) => ({ vendor: x.vendor, model: x.name, ram: x.memorySize, interface: x.interface }))
.filter((x, i, arr) => arr.findIndex((o) => x.vendor === o.vendor && x.model === o.model && x.ram === o.ram && x.interface === o.interface) === i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is hard to understand, ideally I'd imagine this should be extracted into a named function with some vars that would better explain the conditions.

function getDistinctGpuModelsFromNodes(nodes: ProviderSnapshotNode[]) {
const gpuModels = nodes.flatMap((x) => x.gpus).map((x) => ({ vendor: x.vendor, model: x.name, ram: x.memorySize, interface: x.interface }));
const distinctGpuModels = gpuModels.filter(
(x, i, arr) => arr.findIndex((o) => x.vendor === o.vendor && x.model === o.model && x.ram === o.ram && x.interface === o.interface) === i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pls explain what this means?
I understand that findIndex matching same vendor, model, etc. Why should it also be of the same index?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I see, it's to remove duplicates

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really hard to understand this. I'd suggest if we could add a dedicated function for this.

type Matcher<T> = (a: T, b: T) => boolean;

function createFilterUnique<T>(matcher: Matcher<T> = (a, b) => a === b): (value: T, index: number, array: T[]) => boolean {
  return (value, index, array) => {
    return array.findIndex((other) => matcher(value, other)) === index;
  };
}

in this case the code above would be:

const distinctGpuModels = gpuModels.filter(
    createFilterUnique(x, o) => x.vendor === o.vendor && x.model === o.model && x.ram === o.ram && x.interface === o.interface))
);

and example below would be

.filter(createFilterUnique())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be tested here

Copy link
Contributor Author

@Redm4x Redm4x Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to keep only the first occurence of each gpus since there are duplicates in the array. If the current index i matches findIndex that means it's the first occurence so it's kept, otherwise it is filtered out as duplicate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, I figured after asking the question :) check out a suggestion pls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mb your other replies weren't showing when I answered. For sure that would be easier to understand, I'll add it! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the createFilterUnique helper with relevant unit tests

@@ -62,7 +62,7 @@ export const ProviderListRow: React.FunctionComponent<Props> = ({ provider }) =>
const _totalStorage = provider.isOnline
? bytesToShrink(provider.availableStats.storage + provider.pendingStats.storage + provider.activeStats.storage)
: null;
const gpuModels = provider.hardwareGpuModels.map(gpu => gpu.substring(gpu.lastIndexOf(" ") + 1, gpu.length));
const gpuModels = provider.gpuModels.map(x => x.model).filter((x, i, arr) => arr.indexOf(x) === i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also utilise that new filter function. What do you think?

Suggested change
const gpuModels = provider.gpuModels.map(x => x.model).filter((x, i, arr) => arr.indexOf(x) === i);
const gpuModels = provider.gpuModels.map(x => x.model).filter(createFilterUnique());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I added it to the deploy-web project too. No unit tests for now, but we could add them once the big refactor is done (rebrand).

const gpuModels =
provider?.gpuModels
?.map(x => x.model + " " + x.ram)
.filter((x, i, arr) => arr.indexOf(x) === i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.filter((x, i, arr) => arr.indexOf(x) === i)
.filter(createFilterUnique())

@Redm4x Redm4x merged commit ec66e7a into main Apr 4, 2024
5 checks passed
@Redm4x Redm4x deleted the bugfixes/fix-provider-gpus-ui branch April 4, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants