Skip to content

Commit 4a89b60

Browse files
authored
Merge branch 'master' into stdout
2 parents 00db390 + c04dfb2 commit 4a89b60

File tree

13 files changed

+114
-46
lines changed

13 files changed

+114
-46
lines changed

app/server/labml_app/analyses/preferences.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Preferences:
1515
step_range: List[int]
1616
focus_smoothed: bool
1717
smooth_value: float
18+
trim_smooth_ends: float
1819

1920
@classmethod
2021
def defaults(cls):
@@ -23,7 +24,8 @@ def defaults(cls):
2324
errors=[],
2425
step_range=[-1, -1],
2526
focus_smoothed=True,
26-
smooth_value=50 # 50% smooth
27+
smooth_value=50, # 50% smooth
28+
trim_smooth_ends=True
2729
)
2830

2931
def update_preferences(self, data: PreferencesData) -> None:
@@ -42,6 +44,9 @@ def update_preferences(self, data: PreferencesData) -> None:
4244
if 'smooth_value' in data:
4345
self.smooth_value = data['smooth_value']
4446

47+
if 'trim_smooth_ends' in data:
48+
self.trim_smooth_ends = data['trim_smooth_ends']
49+
4550
self.save()
4651

4752
def update_series_preferences(self, data: SeriesPreferences) -> None:
@@ -53,5 +58,6 @@ def get_data(self) -> Dict[str, Any]:
5358
'chart_type': self.chart_type,
5459
'step_range': self.step_range,
5560
'focus_smoothed': self.focus_smoothed,
56-
'smooth_value': self.smooth_value
61+
'smooth_value': self.smooth_value,
62+
'trim_smooth_ends': self.trim_smooth_ends
5763
}

app/ui/src/analyses/experiments/chart_wrapper/card.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Indicator} from "../../../models/run"
33
import {
44
AnalysisPreferenceModel, ComparisonPreferenceModel,
55
} from "../../../models/preferences"
6-
import {getChartType, smoothAndTrimAllCharts, trimSteps} from "../../../components/charts/utils"
6+
import {getChartType, smoothAndTrimAllCharts} from "../../../components/charts/utils"
77
import {LineChart} from "../../../components/charts/lines/chart"
88
import {SparkLines} from "../../../components/charts/spark_lines/chart"
99

@@ -36,6 +36,7 @@ export class CardWrapper {
3636
private stepRange: number[]
3737
private focusSmoothed: boolean
3838
private smoothValue: number
39+
private trimSmoothEnds: boolean
3940

4041
private readonly title?: string
4142

@@ -73,8 +74,9 @@ export class CardWrapper {
7374
this.stepRange = preferenceData.step_range
7475
this.focusSmoothed = preferenceData.focus_smoothed
7576
this.smoothValue = preferenceData.smooth_value
77+
this.trimSmoothEnds = preferenceData.trim_smooth_ends
7678

77-
smoothAndTrimAllCharts(this.series, this.baseSeries, this.smoothValue, this.stepRange)
79+
smoothAndTrimAllCharts(this.series, this.baseSeries, this.smoothValue, this.stepRange, this.trimSmoothEnds)
7880
}
7981

8082
public render() {

app/ui/src/analyses/experiments/chart_wrapper/view.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface MetricDataStore {
3636
focusSmoothed: boolean
3737
stepRange: number[]
3838
smoothValue: number
39+
trimSmoothEnds: boolean
3940

4041
isUnsaved: boolean
4142
}
@@ -100,6 +101,12 @@ namespace ChangeHandlers {
100101
}
101102
}
102103

104+
export class TrimSmoothToggleHandler extends ChangeHandlerBase {
105+
protected handleChange() {
106+
this.wrapper.dataStore.trimSmoothEnds = !this.wrapper.dataStore.trimSmoothEnds
107+
}
108+
}
109+
103110
export class ToggleChangeHandler extends ChangeHandlerBase {
104111
private readonly idx: number
105112
private readonly isBase: boolean
@@ -153,6 +160,7 @@ export class ViewWrapper {
153160
private readonly focusButton: ToggleButton
154161
private readonly smoothSlider: Slider
155162
private readonly deleteButton: DeleteButton
163+
private readonly trimSmoothToggleButton: ToggleButton
156164
private sparkLines: SparkLines
157165

158166
public dataStore: MetricDataStore
@@ -226,6 +234,15 @@ export class ViewWrapper {
226234
parent: this.constructor.name,
227235
onButtonClick: this.onDelete
228236
})
237+
this.trimSmoothToggleButton = new ToggleButton({
238+
onButtonClick: () => {
239+
let changeHandler = new ChangeHandlers.TrimSmoothToggleHandler(this)
240+
changeHandler.change()
241+
},
242+
text: 'Trim Smooth Ends',
243+
isToggled: this.dataStore.trimSmoothEnds,
244+
parent: this.constructor.name
245+
})
229246
}
230247

231248
public clear() {
@@ -316,7 +333,8 @@ export class ViewWrapper {
316333
}
317334

318335
private smoothSeries() {
319-
smoothAndTrimAllCharts(this.dataStore.series, this.dataStore.baseSeries, this.dataStore.smoothValue, this.dataStore.stepRange)
336+
smoothAndTrimAllCharts(this.dataStore.series, this.dataStore.baseSeries,
337+
this.dataStore.smoothValue, this.dataStore.stepRange, this.dataStore.trimSmoothEnds)
320338
}
321339

322340
private renderTopButtons() {
@@ -357,6 +375,7 @@ export class ViewWrapper {
357375
$('div', '.button-row', $ => {
358376
$('span.key', 'Smoothing:')
359377
this.smoothSlider.render($)
378+
this.trimSmoothToggleButton.render($)
360379
})
361380
})
362381
}

app/ui/src/analyses/experiments/comparison/view.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ComparisonView extends ScreenView implements MetricDataStore {
3737
focusSmoothed: boolean
3838
stepRange: number[]
3939
smoothValue: number
40+
trimSmoothEnds: boolean
4041

4142
isUnsaved: boolean
4243

@@ -98,6 +99,7 @@ class ComparisonView extends ScreenView implements MetricDataStore {
9899
this.basePlotIdx = [...this.preferenceData.base_series_preferences]
99100
}
100101
this.smoothValue = this.preferenceData.smooth_value
102+
this.trimSmoothEnds = this.preferenceData.trim_smooth_ends
101103

102104
if (!!this.baseUuid) {
103105
await this.updateBaseRun(force)
@@ -275,7 +277,8 @@ class ComparisonView extends ScreenView implements MetricDataStore {
275277
is_base_distributed: this.baseRun.world_size != 0,
276278
series_names: this.series.map(s => s.name),
277279
base_series_names: this.baseSeries ? this.baseSeries.map(s => s.name) : [],
278-
smooth_value: this.smoothValue
280+
smooth_value: this.smoothValue,
281+
trim_smooth_ends: this.trimSmoothEnds
279282
}
280283

281284
await this.preferenceCache.setPreference(preferenceData)

app/ui/src/analyses/experiments/metrics/view.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class MetricsView extends ScreenView implements MetricDataStore {
5656
stepRange: number[]
5757
smoothValue: number
5858
isUnsaved: boolean
59+
trimSmoothEnds: boolean
5960

6061
constructor(uuid: string, metricUuid?: string) {
6162
super()
@@ -91,6 +92,7 @@ class MetricsView extends ScreenView implements MetricDataStore {
9192
this.focusSmoothed = this.preferenceData.focus_smoothed
9293
this.plotIdx = [...fillPlotPreferences(this.series, this.preferenceData.series_preferences)]
9394
this.smoothValue = this.preferenceData.smooth_value
95+
this.trimSmoothEnds = this.preferenceData.trim_smooth_ends
9496
})
9597

9698
this.refresh = new AwesomeRefreshButton(this.onRefresh.bind(this))
@@ -275,7 +277,8 @@ class MetricsView extends ScreenView implements MetricDataStore {
275277
focus_smoothed: this.focusSmoothed,
276278
sub_series_preferences: undefined,
277279
series_names: this.series.map(s => s.name),
278-
smooth_value: this.smoothValue
280+
smooth_value: this.smoothValue,
281+
trim_smooth_ends: this.trimSmoothEnds
279282
}
280283

281284
if (this.metricUuid == null) {

app/ui/src/components/charts/lines/chart.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import {Indicator} from "../../../models/run"
55
import {
66
getExtent,
77
getLogScale,
8-
getScale,
9-
getSmoothWindow,
10-
smoothSeries,
11-
trimSteps
8+
getScale
129
} from "../utils"
1310
import {LineFill, LinePlot} from "./plot"
1411
import {BottomAxis, RightAxis} from "../axis"
@@ -84,7 +81,9 @@ export class LineChart {
8481
this.baseSeries = this.baseSeries.filter((_, i) => this.basePlotIndex[i] == 1)
8582
this.currentSeries = this.currentSeries.filter((_, i) => this.currentPlotIndex[i] == 1)
8683

87-
const stepExtent = getExtent(this.baseSeries.concat(this.currentSeries).map(s => s.trimmedSeries), d => d.step, false, true)
84+
// get steps from series with at least one value
85+
const series_concat = this.baseSeries.concat(this.currentSeries).filter(s => s.trimmedSeries.length > 0)
86+
const stepExtent = getExtent(series_concat.map(s => s.trimmedSeries), d => d.step, false, true)
8887
this.xScale = getScale(stepExtent, this.chartWidth, false)
8988

9089
this.chartColors = new ChartColors({
@@ -96,7 +95,7 @@ export class LineChart {
9695
chartId = `chart_${Math.round(Math.random() * 1e9)}`
9796

9897
changeScale() {
99-
let plotSeries = this.baseSeries.concat(this.currentSeries).map(s => s.trimmedSeries)
98+
let plotSeries = this.baseSeries.concat(this.currentSeries).map(s => s.trimmedSeries).filter(s => s.length > 0)
10099
if (plotSeries.length == 0) {
101100
this.yScale = d3.scaleLinear()
102101
.domain([0, 0])

app/ui/src/components/charts/lines/plot.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import d3 from "../../../d3"
22
import {WeyaElement, WeyaElementFunction} from '../../../../../lib/weya/weya'
33
import {FillOptions, PlotOptions} from '../types'
44
import {PointValue} from "../../../models/run"
5-
import {getSelectedIdx, mapRange, smoothSeries} from "../utils"
5+
import {getSelectedIdx} from "../utils"
66

77
export interface LinePlotOptions extends PlotOptions {
88
xScale: d3.ScaleLinear<number, number>
@@ -88,6 +88,10 @@ export class LinePlot {
8888
})
8989
})
9090
})
91+
92+
if (this.series.length == 1) { // allways render circle for single point
93+
this.renderCircle(0)
94+
}
9195
}
9296

9397
renderIndicators(cursorStep: number | null) {

app/ui/src/components/charts/spark_lines/chart.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {WeyaElementFunction} from '../../../../../lib/weya/weya'
22
import {ChartOptions} from '../types'
3-
import {getExtent, getSmoothWindow, smoothSeries} from "../utils"
3+
import {getExtent} from "../utils"
44
import {SparkLine} from "./spark_line"
55
import ChartColors from "../chart_colors"
66
import {DefaultLineGradient} from "../chart_gradients"
@@ -56,7 +56,7 @@ export class SparkLines {
5656
const margin = Math.floor(opt.width / 64)
5757
this.rowWidth = Math.min(450, opt.width - Math.max(3 * margin, 60))
5858

59-
this.stepExtent = getExtent(this.currentSeries.concat(this.baseSeries).map(s => s.series), d => d.step)
59+
this.stepExtent = getExtent(this.currentSeries.concat(this.baseSeries).map(s => s.trimmedSeries), d => d.step)
6060

6161
this.chartColors = new ChartColors({nColors: this.uniqueItems.size, secondNColors: this.uniqueItems.size, isDivergent: opt.isDivergent})
6262
}
@@ -82,7 +82,7 @@ export class SparkLines {
8282
}
8383
let sparkLine = new SparkLine({
8484
name: s.name,
85-
series: s.series,
85+
series: s.trimmedSeries,
8686
selected: this.currentPlotIdx[i],
8787
stepExtent: this.stepExtent,
8888
width: this.rowWidth,
@@ -105,7 +105,7 @@ export class SparkLines {
105105
}
106106
let sparkLine = new SparkLine({
107107
name: s.name,
108-
series: s.series,
108+
series: s.trimmedSeries,
109109
selected: this.basePlotIdx[i],
110110
stepExtent: this.stepExtent,
111111
width: this.rowWidth,

app/ui/src/components/charts/spark_lines/spark_line.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class SparkLine {
4141
constructor(opt: SparkLineOptions) {
4242
this.series = opt.series
4343

44-
if (opt.selected == -1) {
44+
if (opt.selected == -1 && this.series.length > 0) {
4545
this.series = [this.series[this.series.length - 1]]
4646
}
4747
this.name = opt.name
@@ -73,12 +73,16 @@ export class SparkLine {
7373

7474
changeCursorValue(cursorStep?: number | null) {
7575
if (this.isSelected) {
76-
this.linePlot.renderIndicators(cursorStep)
76+
this.linePlot?.renderIndicators(cursorStep)
7777
this.renderValue(cursorStep)
7878
}
7979
}
8080

8181
renderValue(cursorStep?: number | null) {
82+
if (this.series.length == 0) {
83+
return
84+
}
85+
8286
const index = this.isSelected ?
8387
getSelectedIdx(this.series, this.bisect, cursorStep) : this.series.length - 1
8488
const last = this.series[index]
@@ -107,6 +111,9 @@ export class SparkLine {
107111
let title = $('span', '.title', this.name, {style: {color: this.color}})
108112
let sparkline = $('svg.sparkline', {style: {width: `${this.chartWidth + this.titleWidth * 2}px`}, height: 36}, $ => {
109113
$('g', {transform: `translate(${this.titleWidth}, 30)`}, $ => {
114+
if (this.series.length == 0) {
115+
return
116+
}
110117
new LineFill({
111118
series: this.series,
112119
xScale: this.xScale,

app/ui/src/components/charts/timeseries/chart.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
getTimeScale,
1010
smooth45,
1111
toDate,
12-
trimSteps
1312
} from "../utils"
1413
import {BottomTimeAxis, RightAxis} from "../axis"
1514
import {TimeSeriesFill, TimeSeriesPlot} from './plot'

0 commit comments

Comments
 (0)