|
| 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