Skip to content

Commit

Permalink
[RUNTIME] Replace random number with UUID (#3544)
Browse files Browse the repository at this point in the history
On a distributed setting, processes from different nodes may have the
same PID. If the seed for `random` is also set, the random number is
also the same, which may finally lead to collision (actually happened on
my cluster).

Changing the random number to `uuid` avoids such collision.
  • Loading branch information
LyricZhao authored Apr 3, 2024
1 parent e14516a commit e8e45a4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/triton/runtime/cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import importlib
import json
import os
import random
import uuid
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Dict, List, Optional
Expand Down Expand Up @@ -113,7 +113,7 @@ def put(self, data, filename, binary=True) -> str:
assert self.lock_path is not None
filepath = self._make_path(filename)
# Random ID to avoid any collisions
rnd_id = random.randint(0, 1000000)
rnd_id = str(uuid.uuid4())
# we use the PID in case a bunch of these around so we can see what PID made it
pid = os.getpid()
# use tempfile to be robust against program interruptions
Expand Down

0 comments on commit e8e45a4

Please sign in to comment.