diff --git a/gen.regression.go b/gen.regression.go index 483d713..7d74ae6 100644 --- a/gen.regression.go +++ b/gen.regression.go @@ -13,6 +13,8 @@ import ( "go/format" "gonum.org/v1/gonum/mat" + "golang.org/x/exp/maps" + "sort" ) type LinearRegression struct { @@ -407,10 +409,11 @@ func {{ .Name }}(width, height uint32, flashAttention bool) uint64 { Degree: 2, } - xs, ys := make([]float64, 0, len(t.x2y)), make([]float64, 0, len(t.x2y)) - for x, y := range t.x2y { - xs = append(xs, x) - ys = append(ys, y*1024*1024) // MB to B + xs := maps.Keys(t.x2y) + sort.Float64s(xs) + ys := make([]float64, len(xs)) + for j, x := range xs { + ys[j] = t.x2y[x] * 1024 * 1024 // MB to B } pr.Fit(xs, ys) @@ -440,10 +443,11 @@ func {{ .Name }}(width, height uint32, flashAttention bool) uint64 { lr := LinearRegression{} - xs, ys := make([]float64, 0, len(t.fax2y)), make([]float64, 0, len(t.fax2y)) - for x, y := range t.fax2y { - xs = append(xs, x) - ys = append(ys, y*1024*1024) // MB to B + xs := maps.Keys(t.fax2y) + sort.Float64s(xs) + ys := make([]float64, len(xs)) + for j, x := range xs { + ys[j] = t.fax2y[x] * 1024 * 1024 // MB to B } lr.Fit(xs, ys) diff --git a/zz_generated.diffusion_model_memory_usage.regression.go b/zz_generated.diffusion_model_memory_usage.regression.go index 5f870f1..4ed421e 100644 --- a/zz_generated.diffusion_model_memory_usage.regression.go +++ b/zz_generated.diffusion_model_memory_usage.regression.go @@ -5,7 +5,7 @@ import "math" // GuessSD1DiffusionModelMemoryUsage returns the memory usage in bytes for the given width and height, // which is calculated by linear regression or polynomial regression. func GuessSD1DiffusionModelMemoryUsage(width, height uint32, flashAttention bool) uint64 { - coefficients := []float64{7.8763685671743e+06, 161.42301986333496, 0.007812489338703485} + coefficients := []float64{7.876368567179878e+06, 161.4230198633402, 0.007812489338703482} degree := 2 x := float64(width * height) @@ -24,7 +24,7 @@ func GuessSD2DiffusionModelMemoryUsage(width, height uint32, flashAttention bool x := float64(width * height) if flashAttention { - coefficients = []float64{3.78068128077788e+06, 513.2102510934714} + coefficients = []float64{3.7806812807775633e+06, 513.2102510934715} degree = 1 } @@ -38,12 +38,12 @@ func GuessSD2DiffusionModelMemoryUsage(width, height uint32, flashAttention bool // GuessSDXLDiffusionModelMemoryUsage returns the memory usage in bytes for the given width and height, // which is calculated by linear regression or polynomial regression. func GuessSDXLDiffusionModelMemoryUsage(width, height uint32, flashAttention bool) uint64 { - coefficients := []float64{5.554129038929968e+07, 138.31961166554433, 0.0006109454572342757} + coefficients := []float64{5.55412903892993e+07, 138.3196116655456, 0.0006109454572342753} degree := 2 x := float64(width * height) if flashAttention { - coefficients = []float64{-5.95880278052181e+06, 500.0687898914631} + coefficients = []float64{-5.958802780521662e+06, 500.06878989146264} degree = 1 } @@ -57,7 +57,7 @@ func GuessSDXLDiffusionModelMemoryUsage(width, height uint32, flashAttention boo // GuessSDXLRefinerDiffusionModelMemoryUsage returns the memory usage in bytes for the given width and height, // which is calculated by linear regression or polynomial regression. func GuessSDXLRefinerDiffusionModelMemoryUsage(width, height uint32, flashAttention bool) uint64 { - coefficients := []float64{4.939599234485548e+07, 155.2477810191175, 0.0007351735797614931} + coefficients := []float64{4.939599234485548e+07, 155.24778101911753, 0.0007351735797614931} degree := 2 x := float64(width * height) @@ -76,7 +76,7 @@ func GuessSDXLRefinerDiffusionModelMemoryUsage(width, height uint32, flashAttent // GuessSD3MediumDiffusionModelMemoryUsage returns the memory usage in bytes for the given width and height, // which is calculated by linear regression or polynomial regression. func GuessSD3MediumDiffusionModelMemoryUsage(width, height uint32, flashAttention bool) uint64 { - coefficients := []float64{1.6529921370035086e+07, 234.66562477184195, 0.0014648995324747492} + coefficients := []float64{1.6529921370034331e+07, 234.6656247718448, 0.0014648995324747485} degree := 2 x := float64(width * height) @@ -104,7 +104,7 @@ func GuessSD35MediumDiffusionModelMemoryUsage(width, height uint32, flashAttenti // GuessSD35LargeDiffusionModelMemoryUsage returns the memory usage in bytes for the given width and height, // which is calculated by linear regression or polynomial regression. func GuessSD35LargeDiffusionModelMemoryUsage(width, height uint32, flashAttention bool) uint64 { - coefficients := []float64{2.320436920291992e+07, 410.3731196298318, 0.002319594715894278} + coefficients := []float64{2.3204369202917013e+07, 410.37311962983387, 0.0023195947158942774} degree := 2 x := float64(width * height) @@ -118,7 +118,7 @@ func GuessSD35LargeDiffusionModelMemoryUsage(width, height uint32, flashAttentio // GuessFLUXDiffusionModelMemoryUsage returns the memory usage in bytes for the given width and height, // which is calculated by linear regression or polynomial regression. func GuessFLUXDiffusionModelMemoryUsage(width, height uint32, flashAttention bool) uint64 { - coefficients := []float64{4.651166867423782e+07, 997.7758807792155, 0.001457339256095295} + coefficients := []float64{4.651166867423724e+07, 997.7758807792177, 0.001457339256095294} degree := 2 x := float64(width * height)