Skip to content

Commit b3e61a1

Browse files
authored
Merge pull request #68 from yuluo-yx/0906-yuluo/add-ttft-ut
2 parents adba622 + 443598c commit b3e61a1

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ttft
2+
3+
import (
4+
"testing"
5+
6+
"github.com/vllm-project/semantic-router/semantic-router/pkg/config"
7+
)
8+
9+
func TestComputeBaseTTFT(t *testing.T) {
10+
11+
gpuConfig := config.GPUConfig{
12+
FLOPS: 1e12, // 1 TFLOP
13+
HBM: 1e11, // 100 GB/s
14+
}
15+
calculator := NewCalculator(gpuConfig)
16+
17+
routerCfg := &config.RouterConfig{}
18+
// Mock config methods if needed, or set up fields so that
19+
// GetModelParamCount, GetModelBatchSize, GetModelContextSize return defaults
20+
21+
ttft := calculator.ComputeBaseTTFT("test-model", routerCfg)
22+
if ttft <= 0 {
23+
t.Errorf("Expected TTFT > 0, got %f", ttft)
24+
}
25+
}
26+
27+
func TestInitializeModelTTFT(t *testing.T) {
28+
gpuConfig := config.GPUConfig{
29+
FLOPS: 1e12,
30+
HBM: 1e11,
31+
}
32+
calculator := NewCalculator(gpuConfig)
33+
34+
// Minimal mock config with two categories and models
35+
routerCfg := &config.RouterConfig{
36+
Categories: []config.Category{
37+
{
38+
ModelScores: []config.ModelScore{
39+
{Model: "model-a", Score: 0.9},
40+
{Model: "model-b", Score: 0.8},
41+
},
42+
},
43+
},
44+
DefaultModel: "model-default",
45+
}
46+
47+
modelTTFT := calculator.InitializeModelTTFT(routerCfg)
48+
if len(modelTTFT) != 3 {
49+
t.Errorf("Expected 3 models in TTFT map, got %d", len(modelTTFT))
50+
}
51+
for model, ttft := range modelTTFT {
52+
if ttft <= 0 {
53+
t.Errorf("Model %s has non-positive TTFT: %f", model, ttft)
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)