Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Stop the chart metric formatters truncating values of 1000 and up (#8724)

Vineeth Sai Varikuntla035658f1aff1
diff --git a/studio/frontend/src/features/studio/sections/charts/utils.ts b/studio/frontend/src/features/studio/sections/charts/utils.ts
index d3b2ff3ed32..8d22bea380a 100644
--- a/studio/frontend/src/features/studio/sections/charts/utils.ts
+++ b/studio/frontend/src/features/studio/sections/charts/utils.ts
@@ -11,6 +11,16 @@ export const DEFAULT_Y_AXIS_WIDTH = 45;
const TRAILING_ZEROES_RE = /\.?0+$/;
const NEGATIVE_ZERO_RE = /^-0$/;
+// Trailing zeroes are only padding after a decimal point. toFixed(0) produces
+// none, and stripping them from a plain integer eats real digits: "25000" would
+// come back as "25", and "1000000" as "1".
+function trimFormatted(text: string): string {
+ const trimmed = text.includes(".")
+ ? text.replace(TRAILING_ZEROES_RE, "")
+ : text;
+ return trimmed.replace(NEGATIVE_ZERO_RE, "0");
+}
+
export const placeholderEvalData = [
{ step: 0, loss: 2.8 },
{ step: 50, loss: 2.4 },
@@ -49,10 +59,7 @@ export function formatMetric(value: number): string {
decimals = 8;
}
- return value
- .toFixed(decimals)
- .replace(TRAILING_ZEROES_RE, "")
- .replace(NEGATIVE_ZERO_RE, "0");
+ return trimFormatted(value.toFixed(decimals));
}
export function formatAxisMetric(value: number): string {
@@ -75,10 +82,7 @@ export function formatAxisMetric(value: number): string {
decimals = 5;
}
- return value
- .toFixed(decimals)
- .replace(TRAILING_ZEROES_RE, "")
- .replace(NEGATIVE_ZERO_RE, "0");
+ return trimFormatted(value.toFixed(decimals));
}
export function formatStepTick(value: number): string {
diff --git a/studio/frontend/tests/chart-metric-formatting.test.ts b/studio/frontend/tests/chart-metric-formatting.test.ts
new file mode 100644
index 00000000000..c02966f2ab3
--- /dev/null
+++ b/studio/frontend/tests/chart-metric-formatting.test.ts
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// Both formatters drop to zero decimals at 1000, so the trailing-zero trim has
+// no decimal point left to work on and used to eat significant digits.
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import {
+ formatAxisMetric,
+ formatMetric,
+} from "../src/features/studio/sections/charts/utils.ts";
+
+test("a large metric keeps every digit", () => {
+ for (const [value, expected] of [
+ [1000, "1000"],
+ [1500, "1500"],
+ [2000, "2000"],
+ [12_000, "12000"],
+ [25_000, "25000"],
+ [1_000_000, "1000000"],
+ [-2000, "-2000"],
+ ] as [number, string][]) {
+ assert.equal(formatMetric(value), expected, `formatMetric(${value})`);
+ assert.equal(
+ formatAxisMetric(value),
+ expected,
+ `formatAxisMetric(${value})`,
+ );
+ }
+});
+
+test("a large metric with a fraction still rounds to whole digits", () => {
+ assert.equal(formatMetric(3000.4), "3000");
+ assert.equal(formatAxisMetric(3000.4), "3000");
+});
+
+test("padding after a decimal point is still trimmed", () => {
+ assert.equal(formatMetric(999.5), "999.5");
+ assert.equal(formatMetric(100), "100");
+ assert.equal(formatMetric(1), "1");
+ assert.equal(formatMetric(0.5), "0.5");
+ assert.equal(formatMetric(0.01), "0.01");
+ assert.equal(formatAxisMetric(100), "100");
+ assert.equal(formatAxisMetric(2.5), "2.5");
+});
+
+test("negative zero reads as zero", () => {
+ assert.equal(formatMetric(-0), "0");
+ assert.equal(formatAxisMetric(-0), "0");
+ // toFixed rounds this to "-0" before the trim sees it.
+ assert.equal(formatAxisMetric(-0.000001), "0");
+});
+
+test("a non-finite metric is still reported as zero", () => {
+ for (const value of [Number.NaN, Number.POSITIVE_INFINITY]) {
+ assert.equal(formatMetric(value), "0");
+ assert.equal(formatAxisMetric(value), "0");
+ }
+});
+
+test("no formatted metric is shorter than its integer part", () => {
+ // The original defect showed up as silent truncation, so pin the invariant
+ // rather than only the values that happened to trigger it.
+ for (let value = 1; value <= 2_000_000; value *= 10) {
+ for (const scale of [1, 2, 5, 25]) {
+ const metric = value * scale;
+ const digits = String(Math.trunc(metric)).length;
+ for (const [name, formatted] of [
+ ["formatMetric", formatMetric(metric)],
+ ["formatAxisMetric", formatAxisMetric(metric)],
+ ] as [string, string][]) {
+ assert.ok(
+ formatted.replace("-", "").split(".")[0].length >= digits,
+ `${name}(${metric}) = ${formatted} lost digits`,
+ );
+ }
+ }
+ }
+});