Show all logged metrics on the loss graph

This commit is contained in:
Jaret Burkett
2026-06-08 09:43:03 -06:00
parent e281df70dd
commit d7f8887bbf
2 changed files with 99 additions and 63 deletions

View File

@@ -11,12 +11,6 @@ export interface LossPoint {
type SeriesMap = Record<string, LossPoint[]>;
function isLossKey(key: string) {
// treat anything containing "loss" as a loss-series
// (covers loss, train_loss, val_loss, loss/xyz, etc.)
return /loss/i.test(key);
}
export default function useJobLossLog(jobID: string, reloadInterval: null | number = null) {
const [series, setSeries] = useState<SeriesMap>({});
const [keys, setKeys] = useState<string[]>([]);
@@ -29,10 +23,10 @@ export default function useJobLossLog(jobID: string, reloadInterval: null | numb
const lastStepByKeyRef = useRef<Record<string, number | null>>({});
const lossKeys = useMemo(() => {
const base = (keys ?? []).filter(isLossKey);
const base = keys ?? [];
// if keys table is empty early on, fall back to just "loss"
if (base.length === 0) return ['loss'];
return base.sort();
return [...base].sort();
}, [keys]);
const refreshLoss = useCallback(async () => {
@@ -54,7 +48,7 @@ export default function useJobLossLog(jobID: string, reloadInterval: null | numb
const newKeys = first.keys ?? [];
setKeys(newKeys);
const wantedLossKeys = (newKeys.filter(isLossKey).length ? newKeys.filter(isLossKey) : ['loss']).sort();
const wantedLossKeys = (newKeys.length ? [...newKeys] : ['loss']).sort();
// Step 2: fetch each loss key incrementally (since_step per key if polling)
const requests = wantedLossKeys.map(k => {
@@ -100,9 +94,9 @@ export default function useJobLossLog(jobID: string, reloadInterval: null | numb
: (lastStepByKeyRef.current[k] ?? null);
}
// remove stale loss keys that no longer exist (rare, but keeps UI clean)
// remove stale keys that no longer exist (rare, but keeps UI clean)
for (const existingKey of Object.keys(next)) {
if (isLossKey(existingKey) && !wantedLossKeys.includes(existingKey)) {
if (!wantedLossKeys.includes(existingKey)) {
delete next[existingKey];
delete lastStepByKeyRef.current[existingKey];
}