diff --git a/pkg/common/utils.go b/pkg/common/utils.go index d937d866..692707a0 100644 --- a/pkg/common/utils.go +++ b/pkg/common/utils.go @@ -17,6 +17,7 @@ limitations under the License. package common import ( + "fmt" "math/rand" "regexp" "sync" @@ -53,13 +54,18 @@ func ValidateContextWindow(promptTokens int, maxCompletionTokens *int64, maxMode type Random struct { randomGenerator *rand.Rand randMutex sync.Mutex + uuidNamespace uuid.UUID + uuidName string + uuidCount int } -func NewRandom(seed int64) *Random { +func NewRandom(seed int64, port int) *Random { src := rand.NewSource(seed) randomGenerator := rand.New(src) - uuid.SetRand(rand.New(rand.NewSource(seed))) - return &Random{randomGenerator: randomGenerator} + return &Random{randomGenerator: randomGenerator, + uuidNamespace: uuid.NameSpaceURL, + uuidName: fmt.Sprintf("%d-%d", seed, port), + } } // Returns an integer between min and max (included) @@ -122,7 +128,9 @@ func (r *Random) RandomNormTruncated(mean int, stddev int) int { func (r *Random) GenerateUUIDString() string { r.randMutex.Lock() defer r.randMutex.Unlock() - return uuid.NewString() + name := fmt.Sprintf("%s-%d", r.uuidName, r.uuidCount) + r.uuidCount++ + return uuid.NewSHA1(r.uuidNamespace, []byte(name)).String() } func (r *Random) RandomNumericString(length int) string { diff --git a/pkg/dataset/custom_dataset_test.go b/pkg/dataset/custom_dataset_test.go index f406be36..e30141d8 100644 --- a/pkg/dataset/custom_dataset_test.go +++ b/pkg/dataset/custom_dataset_test.go @@ -50,7 +50,7 @@ var _ = Describe("CustomDataset", Ordered, func() { ) BeforeAll(func() { - random = common.NewRandom(time.Now().UnixNano()) + random = common.NewRandom(time.Now().UnixNano(), 8080) }) BeforeEach(func() { diff --git a/pkg/dataset/dataset_test.go b/pkg/dataset/dataset_test.go index 2e978fc5..3e7974a8 100644 --- a/pkg/dataset/dataset_test.go +++ b/pkg/dataset/dataset_test.go @@ -34,7 +34,7 @@ var _ = Describe("Dataset", Ordered, func() { ) BeforeAll(func() { - random = common.NewRandom(time.Now().UnixNano()) + random = common.NewRandom(time.Now().UnixNano(), 8080) }) BeforeEach(func() { diff --git a/pkg/kv-cache/kv_cache_test.go b/pkg/kv-cache/kv_cache_test.go index ebfbc32e..029bbfe2 100644 --- a/pkg/kv-cache/kv_cache_test.go +++ b/pkg/kv-cache/kv_cache_test.go @@ -121,7 +121,7 @@ type threadTestCase struct { } var _ = Describe("KV cache", Ordered, func() { - random := common.NewRandom(time.Now().UnixNano()) + random := common.NewRandom(time.Now().UnixNano(), 8080) Context("general tests", func() { // check single request processing, ensure cache is valid after request processing started diff --git a/pkg/llm-d-inference-sim/failures_test.go b/pkg/llm-d-inference-sim/failures_test.go index 2a2756f3..1cb3b241 100644 --- a/pkg/llm-d-inference-sim/failures_test.go +++ b/pkg/llm-d-inference-sim/failures_test.go @@ -35,7 +35,7 @@ var _ = Describe("Failures", func() { Describe("getRandomFailure", Ordered, func() { var random *common.Random BeforeAll(func() { - random = common.NewRandom(time.Now().UnixNano()) + random = common.NewRandom(time.Now().UnixNano(), 8080) }) It("should return a failure from all types when none specified", func() { diff --git a/pkg/llm-d-inference-sim/latencies_test.go b/pkg/llm-d-inference-sim/latencies_test.go index 97435763..886168f3 100644 --- a/pkg/llm-d-inference-sim/latencies_test.go +++ b/pkg/llm-d-inference-sim/latencies_test.go @@ -43,7 +43,7 @@ var _ = Describe("Check random latencies", Ordered, func() { simulator.metrics.runReqChan = make(chan int64, 100) - simulator.random = common.NewRandom(time.Now().UnixNano()) + simulator.random = common.NewRandom(time.Now().UnixNano(), 8080) }) DescribeTable("should calculate inter token latency correctly", diff --git a/pkg/llm-d-inference-sim/simulator.go b/pkg/llm-d-inference-sim/simulator.go index 6eddace5..6fafe9b1 100644 --- a/pkg/llm-d-inference-sim/simulator.go +++ b/pkg/llm-d-inference-sim/simulator.go @@ -282,7 +282,7 @@ func (s *VllmSimulator) startSim(ctx context.Context) error { } func (s *VllmSimulator) initializeSim(ctx context.Context) error { - s.random = common.NewRandom(s.config.Seed) + s.random = common.NewRandom(s.config.Seed, s.config.Port) for _, lora := range s.config.LoraModules { s.loraAdaptors.Store(lora.Name, "")