Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pkg/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package common

import (
"fmt"
"math/rand"
"regexp"
"sync"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dataset/custom_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dataset/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv-cache/kv_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/llm-d-inference-sim/failures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/llm-d-inference-sim/latencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pkg/llm-d-inference-sim/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down