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

Handle perturbations in run predictions frontend #2950

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 6 additions & 3 deletions helm-frontend/src/components/InstanceData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ export default function InstanceData({
predictions,
metricFieldMap,
}: Props) {
const renderInstanceId = (instance: Instance): string => {
return instance.perturbation === undefined
? `Instance id: ${instance.id} [split: ${instance.split}]`
: `Instance id: ${instance.id} [split: ${instance.split}][perturbation: ${instance.perturbation.name}]`;
};
return (
<div className="border p-4">
<h3 className="text-xl mb-4">
{`Instance id: ${instance.id} [split: ${instance.split}]`}
</h3>
<h3 className="text-xl mb-4">{renderInstanceId(instance)}</h3>
<h3>Input</h3>
{instance.input.multimedia_content !== undefined ? (
<MultimediaObjectDisplay
Expand Down
4 changes: 3 additions & 1 deletion helm-frontend/src/components/Predictions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export default function Predictions({
<div className="flex flex-wrap justify-start items-start">
{predictions.map((prediction, idx) => (
<div className="w-full" key={idx}>
{predictions.length > 1 ? <h2>Trial {idx}</h2> : null}
{predictions.length > 1 ? (
<h2>Trial {prediction.train_trial_index}</h2>
) : null}
<div className="mt-2 w-full">
{prediction.base64_images &&
prediction.base64_images.length > 0 ? (
Expand Down
77 changes: 52 additions & 25 deletions helm-frontend/src/routes/Run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import type Instance from "@/types/Instance";
import getStatsByName from "@/services/getStatsByName";
import type Stat from "@/types/Stat";
import getDisplayRequestsByName from "@/services/getDisplayRequestsByName";
import type DisplayRequestsMap from "@/types/DisplayRequestsMap";
import getDisplayPredictionsByName from "@/services/getDisplayPredictionsByName";
import type DisplayPredictionsMap from "@/types/DisplayPredictionsMap";
import getScenarioByName from "@/services/getScenarioByName";
import type Scenario from "@/types/Scenario";
import type AdapterFieldMap from "@/types/AdapterFieldMap";
Expand All @@ -32,6 +30,8 @@ import MarkdownValue from "@/components/MarkdownValue";
import StatNameDisplay from "@/components/StatNameDisplay";
import getRunsToRunSuites from "@/services/getRunsToRunSuites";
import getSuiteForRun from "@/services/getSuiteForRun";
import DisplayPrediction from "@/types/DisplayPrediction";
import DisplayRequest from "@/types/DisplayRequest";

const INSTANCES_PAGE_SIZE = 10;
const METRICS_PAGE_SIZE = 50;
Expand All @@ -45,10 +45,10 @@ export default function Run() {
const [instances, setInstances] = useState<Instance[]>([]);
const [stats, setStats] = useState<Stat[]>([]);
const [displayPredictionsMap, setDisplayPredictionsMap] = useState<
DisplayPredictionsMap | undefined
undefined | { [key: string]: { [key: string]: DisplayPrediction[] } }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: undefined | Record<string, Record<string, DisplayPrediction[]>> is a little cleaner

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

>();
const [displayRequestsMap, setDisplayRequestsMap] = useState<
DisplayRequestsMap | undefined
undefined | { [key: string]: { [key: string]: DisplayRequest[] } }
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above about Record

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

>();
const [currentInstancesPage, setCurrentInstancesPage] = useState<number>(1);
const [totalInstancesPages, setTotalInstancesPages] = useState<number>(1);
Expand Down Expand Up @@ -81,13 +81,15 @@ export default function Run() {
scenario,
displayPredictions,
displayRequests,
schema,
] = await Promise.all([
getRunSpecs(signal),
getInstances(runName, signal, suite),
getStatsByName(runName, signal, suite),
getScenarioByName(runName, signal, suite),
getDisplayPredictionsByName(runName, signal, suite),
getDisplayRequestsByName(runName, signal, suite),
getSchema(signal),
]);

setRunSpec(runSpecs.find((rs) => rs.name === runName));
Expand All @@ -110,25 +112,42 @@ export default function Run() {
setCurrentMetricsPage(
Math.max(Math.min(metricPage, totalMetricsPages), 1),
);
setDisplayPredictionsMap(
displayPredictions.reduce((acc, cur) => {
if (acc[cur.instance_id] === undefined) {
acc[cur.instance_id] = [];
}
acc[cur.instance_id].push(cur);
return acc;
}, {} as DisplayPredictionsMap),
);
setDisplayRequestsMap(
displayRequests.reduce((acc, cur) => {
if (acc[cur.instance_id] === undefined) {
acc[cur.instance_id] = [];
}
acc[cur.instance_id].push(cur);
return acc;
}, {} as DisplayRequestsMap),
);
const schema = await getSchema(signal);

const displayRequestsArgh: {
[key: string]: { [key: string]: DisplayRequest[] };
} = {};
displayRequests.forEach((displayRequest) => {
const instanceId = displayRequest.instance_id;
const perturbationName = displayRequest.perturbation?.name || "";
if (displayRequestsArgh[instanceId] === undefined) {
displayRequestsArgh[instanceId] = {};
}
if (displayRequestsArgh[instanceId][perturbationName] === undefined) {
displayRequestsArgh[instanceId][perturbationName] = [];
}
displayRequestsArgh[instanceId][perturbationName].push(displayRequest);
});
setDisplayRequestsMap(displayRequestsArgh);

const displayPredictionsArgh: {
[key: string]: { [key: string]: DisplayPrediction[] };
} = {};
displayPredictions.forEach((displayPrediction) => {
const instanceId = displayPrediction.instance_id;
const perturbationName = displayPrediction.perturbation?.name || "";
if (displayPredictionsArgh[instanceId] === undefined) {
displayPredictionsArgh[instanceId] = {};
}
if (
displayPredictionsArgh[instanceId][perturbationName] === undefined
) {
displayPredictionsArgh[instanceId][perturbationName] = [];
}
displayPredictionsArgh[instanceId][perturbationName].push(
displayPrediction,
);
});
setDisplayPredictionsMap(displayPredictionsArgh);

setMetricFieldMap(
schema.metrics.reduce((acc, cur) => {
Expand Down Expand Up @@ -268,8 +287,16 @@ export default function Run() {
<InstanceData
key={`${instance.id}-${idx}`}
instance={instance}
requests={displayRequestsMap[instance.id]}
predictions={displayPredictionsMap[instance.id]}
requests={
displayRequestsMap[instance.id][
instance.perturbation?.name || ""
]
}
predictions={
displayPredictionsMap[instance.id][
instance.perturbation?.name || ""
]
}
metricFieldMap={metricFieldMap}
/>
))}
Expand Down
2 changes: 2 additions & 0 deletions helm-frontend/src/types/DisplayPrediction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CompletionAnnotation from "./CompletionAnnotation";
import Perturbation from "./Perturbation";

export default interface DisplayPrediction {
instance_id: string;
Expand All @@ -16,4 +17,5 @@ export default interface DisplayPrediction {
base64_images?: string[] | undefined;
// beware you will have to update this for future custom annotations
annotations?: Record<string, Array<CompletionAnnotation>> | undefined;
perturbation?: Perturbation | undefined;
}
5 changes: 0 additions & 5 deletions helm-frontend/src/types/DisplayPredictionsMap.ts

This file was deleted.

2 changes: 2 additions & 0 deletions helm-frontend/src/types/DisplayRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MultimediaObject from "@/types/MultimediaObject";
import Perturbation from "./Perturbation";

export default interface DisplayRequest {
instance_id: string;
Expand All @@ -18,4 +19,5 @@ export default interface DisplayRequest {
top_p: number;
multimodal_prompt: MultimediaObject | undefined;
};
perturbation?: Perturbation | undefined;
}
5 changes: 0 additions & 5 deletions helm-frontend/src/types/DisplayRequestsMap.ts

This file was deleted.

2 changes: 2 additions & 0 deletions helm-frontend/src/types/Instance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MultimediaObject from "@/types/MultimediaObject";
import type Reference from "@/types/Reference";
import Perturbation from "./Perturbation";

export default interface Instance {
id: string;
Expand All @@ -9,4 +10,5 @@ export default interface Instance {
multimedia_content: MultimediaObject | undefined;
};
references: Reference[];
perturbation?: Perturbation | undefined;
}