ir_model 教程
本教程直接以 Plot IR 构建报告文档,这样你就可以发布并非来自 JSONL 流的结果,例如调优扫描或用 stats 计算的摘要。
快速上手
moon add Luna-Flow/mare_mark@0.3.0
import {
"Luna-Flow/mare_mark/model",
"Luna-Flow/mare_mark/ir_model",
"Luna-Flow/mare_mark/report",
"Luna-Flow/mare_mark/stats",
}
test "a document by hand" {
let points = [
@ir_model.PlotPoint::new("64", 0.8, "scalar"),
@ir_model.PlotPoint::new("128", 3.1, "scalar"),
@ir_model.PlotPoint::new("64", 0.5, "blocked"),
@ir_model.PlotPoint::new("128", 1.4, "blocked"),
]
let plot = @ir_model.Plot::new(@ir_model.PlotKind::Scaling, "GEMM time", "ms/op", "median", points)
let document = @ir_model.PlotDocument::new("sweep-1", "native", [plot])
inspect(@report.html(document).contains("GEMM time"), content="true")
}
日常任务
绘制比较结果
把 stats 的比较结果转化为区间图,每个数据集一个点:
test "interval plot from comparisons" {
let baseline = [[100.0, 101.0, 99.0], [400.0, 404.0, 398.0]]
let candidate = [[90.0, 92.0, 91.0], [410.0, 409.0, 412.0]]
let points = []
for dataset in 0..<2 {
let result = @stats.compare_paired(
"baseline", "candidate", baseline[dataset], candidate[dataset], 2.0, @model.confirmatory_interval(),
)
points.push(@ir_model.PlotPoint::new(dataset.to_string(), result.relative_delta_pct, "candidate"))
}
let plot = @ir_model.Plot::new(@ir_model.PlotKind::Interval, "Relative median delta", "%", "point estimate", points)
inspect(plot.points[0].y, content="-9")
inspect(plot.points[1].y, content="2.5")
}
附加正确性证据
test "differential evidence" {
let corpus = @ir_model.CorpusSummary::new(200, 197, 2, 1, 0)
let report = @ir_model.DifferentialReport::new([], [@ir_model.CapabilityCell::new("fast", "unsupported", 1)], [], corpus)
let document = @ir_model.PlotDocument::new("corpus-run", "native", [], differential=report)
inspect(@report.html(document).contains("failed 2"), content="true")
}
更进一步
用 @report.plot_svg 渲染,把一张图表嵌入你自己的页面,或者用 @report.plot_json 导出给其他工具;参见 report API。
常见陷阱
- 数值型的 x 值。 它们是字符串,并按首次出现的顺序均匀排布;如果顺序重要,请对点进行排序。
- 空的系列名称。 它们被绘制为
value。