Skip to content

Commit dc055d6

Browse files
authored
Deterministic uuid (#245)
Signed-off-by: irar2 <[email protected]>
1 parent 5a098a8 commit dc055d6

File tree

7 files changed

+18
-10
lines changed

7 files changed

+18
-10
lines changed

pkg/common/utils.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package common
1818

1919
import (
20+
"fmt"
2021
"math/rand"
2122
"regexp"
2223
"sync"
@@ -53,13 +54,18 @@ func ValidateContextWindow(promptTokens int, maxCompletionTokens *int64, maxMode
5354
type Random struct {
5455
randomGenerator *rand.Rand
5556
randMutex sync.Mutex
57+
uuidNamespace uuid.UUID
58+
uuidName string
59+
uuidCount int
5660
}
5761

58-
func NewRandom(seed int64) *Random {
62+
func NewRandom(seed int64, port int) *Random {
5963
src := rand.NewSource(seed)
6064
randomGenerator := rand.New(src)
61-
uuid.SetRand(rand.New(rand.NewSource(seed)))
62-
return &Random{randomGenerator: randomGenerator}
65+
return &Random{randomGenerator: randomGenerator,
66+
uuidNamespace: uuid.NameSpaceURL,
67+
uuidName: fmt.Sprintf("%d-%d", seed, port),
68+
}
6369
}
6470

6571
// Returns an integer between min and max (included)
@@ -122,7 +128,9 @@ func (r *Random) RandomNormTruncated(mean int, stddev int) int {
122128
func (r *Random) GenerateUUIDString() string {
123129
r.randMutex.Lock()
124130
defer r.randMutex.Unlock()
125-
return uuid.NewString()
131+
name := fmt.Sprintf("%s-%d", r.uuidName, r.uuidCount)
132+
r.uuidCount++
133+
return uuid.NewSHA1(r.uuidNamespace, []byte(name)).String()
126134
}
127135

128136
func (r *Random) RandomNumericString(length int) string {

pkg/dataset/custom_dataset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var _ = Describe("CustomDataset", Ordered, func() {
5050
)
5151

5252
BeforeAll(func() {
53-
random = common.NewRandom(time.Now().UnixNano())
53+
random = common.NewRandom(time.Now().UnixNano(), 8080)
5454
})
5555

5656
BeforeEach(func() {

pkg/dataset/dataset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var _ = Describe("Dataset", Ordered, func() {
3434
)
3535

3636
BeforeAll(func() {
37-
random = common.NewRandom(time.Now().UnixNano())
37+
random = common.NewRandom(time.Now().UnixNano(), 8080)
3838
})
3939

4040
BeforeEach(func() {

pkg/kv-cache/kv_cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ type threadTestCase struct {
121121
}
122122

123123
var _ = Describe("KV cache", Ordered, func() {
124-
random := common.NewRandom(time.Now().UnixNano())
124+
random := common.NewRandom(time.Now().UnixNano(), 8080)
125125

126126
Context("general tests", func() {
127127
// check single request processing, ensure cache is valid after request processing started

pkg/llm-d-inference-sim/failures_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var _ = Describe("Failures", func() {
3535
Describe("getRandomFailure", Ordered, func() {
3636
var random *common.Random
3737
BeforeAll(func() {
38-
random = common.NewRandom(time.Now().UnixNano())
38+
random = common.NewRandom(time.Now().UnixNano(), 8080)
3939
})
4040

4141
It("should return a failure from all types when none specified", func() {

pkg/llm-d-inference-sim/latencies_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var _ = Describe("Check random latencies", Ordered, func() {
4343

4444
simulator.metrics.runReqChan = make(chan int64, 100)
4545

46-
simulator.random = common.NewRandom(time.Now().UnixNano())
46+
simulator.random = common.NewRandom(time.Now().UnixNano(), 8080)
4747
})
4848

4949
DescribeTable("should calculate inter token latency correctly",

pkg/llm-d-inference-sim/simulator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (s *VllmSimulator) startSim(ctx context.Context) error {
282282
}
283283

284284
func (s *VllmSimulator) initializeSim(ctx context.Context) error {
285-
s.random = common.NewRandom(s.config.Seed)
285+
s.random = common.NewRandom(s.config.Seed, s.config.Port)
286286

287287
for _, lora := range s.config.LoraModules {
288288
s.loraAdaptors.Store(lora.Name, "")

0 commit comments

Comments
 (0)