|
47 | 47 |
|
48 | 48 | logger = init_logger(__name__) |
49 | 49 |
|
| 50 | +_PATH_SLASH_REPLACEMENT = "-SEP-" |
| 51 | + |
50 | 52 |
|
51 | 53 | # --------------------------------------------------------------- |
52 | 54 | # ObjectKey <-> file path helpers |
|
56 | 58 | def _object_key_to_filename(key: ObjectKey) -> str: |
57 | 59 | """Derive a deterministic file name from an ObjectKey.""" |
58 | 60 | chunk_hex = key.chunk_hash.hex() |
59 | | - return f"{key.model_name}_{key.kv_rank:08x}_{chunk_hex}.bin" |
| 61 | + safe_model_name = key.model_name.replace("/", _PATH_SLASH_REPLACEMENT) |
| 62 | + return f"{safe_model_name}_{key.kv_rank:08x}_{chunk_hex}.bin" |
60 | 63 |
|
61 | 64 |
|
62 | 65 | def _filename_to_object_key(filename: str) -> ObjectKey: |
63 | 66 | """Reverse a filename produced by ``_object_key_to_filename``.""" |
64 | 67 | stem = filename.removesuffix(".bin") |
65 | 68 | # Split from the right: last part is chunk_hash, second-last is kv_rank |
66 | 69 | parts = stem.rsplit("_", 2) |
67 | | - model_name = parts[0] |
| 70 | + model_name = parts[0].replace(_PATH_SLASH_REPLACEMENT, "/") |
68 | 71 | kv_rank = int(parts[1], 16) |
69 | 72 | chunk_hash = bytes.fromhex(parts[2]) |
70 | 73 | return ObjectKey(chunk_hash=chunk_hash, model_name=model_name, kv_rank=kv_rank) |
@@ -453,7 +456,9 @@ def persist(self, config: PersistConfig) -> bool: |
453 | 456 | } |
454 | 457 | entries.append(entry) |
455 | 458 |
|
456 | | - os.makedirs(os.path.dirname(config.persist_path), exist_ok=True) |
| 459 | + persist_dir = os.path.dirname(config.persist_path) |
| 460 | + if persist_dir: |
| 461 | + os.makedirs(persist_dir, exist_ok=True) |
457 | 462 | with open(config.persist_path, "w") as f: |
458 | 463 | json.dump(entries, f) |
459 | 464 |
|
|
0 commit comments