Skip to content

Commit 5b8af43

Browse files
authored
Fix cache meta loading on windows (#802)
1 parent 61c070f commit 5b8af43

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ At its core, MLCFlow relies on a single powerful automation, the Script, which i
3131
## 🤝 Contributing
3232
We welcome contributions from the community! To contribute:
3333
1. Submit pull requests (PRs) to the **`dev`** branch.
34-
2. Review our [CONTRIBUTORS.md](here) for guidelines and best practices.
34+
2. See [here](CONTRIBUTORS.md) for guidelines and best practices on contribution.
3535
3. Explore more about MLPerf Inference automation in the official [MLPerf Inference Documentation](https://docs.mlcommons.org/inference/).
3636

3737
Your contributions help drive the project forward!
@@ -61,6 +61,7 @@ This project is made possible through the generous support of:
6161
- [cKnowledge.org](https://cKnowledge.org)
6262
- [cTuning Foundation](https://cTuning.org)
6363
- [GATEOverflow](https://gateoverflow.in)
64+
- [AMD](https://www.amd.com)
6465
- [MLCommons](https://mlcommons.org)
6566

6667
We appreciate their contributions and sponsorship!

automation/script/cache_utils.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -430,40 +430,52 @@ def find_cached_script(i):
430430

431431
def fix_cache_paths(cached_path, env):
432432

433-
current_cache_path = cached_path
433+
current_cache_path = os.path.normpath(cached_path)
434434

435435
new_env = env # just a reference
436436

437+
def normalize_and_replace_path(path_str):
438+
"""Helper to normalize and replace cache paths in a string."""
439+
# Normalize the path to use the current OS separators
440+
normalized = os.path.normpath(path_str)
441+
442+
# Check if path contains local/cache or local\cache pattern
443+
path_parts = normalized.split(os.sep)
444+
445+
try:
446+
local_idx = path_parts.index("local")
447+
if local_idx + \
448+
1 < len(path_parts) and path_parts[local_idx + 1] == "cache":
449+
# Extract the loaded cache path (up to and including "cache")
450+
loaded_cache_path = os.sep.join(path_parts[:local_idx + 2])
451+
loaded_cache_path_norm = os.path.normpath(loaded_cache_path)
452+
453+
if loaded_cache_path_norm != current_cache_path and os.path.exists(
454+
current_cache_path):
455+
# Replace old cache path with current cache path
456+
return normalized.replace(
457+
loaded_cache_path_norm, current_cache_path)
458+
except (ValueError, IndexError):
459+
# "local" not in path or malformed path
460+
pass
461+
462+
return normalized
463+
437464
for key, val in new_env.items():
438-
# Check for a path separator in a string and determine the
439-
# separator
440-
if isinstance(val, str) and any(sep in val for sep in [
441-
"/local/cache/", "\\local\\cache\\"]):
442-
sep = "/" if "/local/cache/" in val else "\\"
443-
444-
path_split = val.split(sep)
445-
repo_entry_index = path_split.index("local")
446-
loaded_cache_path = sep.join(
447-
path_split[0:repo_entry_index + 2])
448-
if loaded_cache_path != current_cache_path and os.path.exists(
449-
current_cache_path):
450-
new_env[key] = val.replace(
451-
loaded_cache_path, current_cache_path).replace(sep, "/")
465+
if isinstance(val, str):
466+
# Check if path contains cache directory pattern
467+
normalized_val = val.replace('\\', os.sep).replace('/', os.sep)
468+
if os.sep.join(['local', 'cache']) in normalized_val:
469+
new_env[key] = normalize_and_replace_path(val)
452470

453471
elif isinstance(val, list):
454472
for i, val2 in enumerate(val):
455-
if isinstance(val2, str) and any(sep in val2 for sep in [
456-
"/local/cache/", "\\local\\cache\\"]):
457-
sep = "/" if "/local/cache/" in val2 else "\\"
458-
459-
path_split = val2.split(sep)
460-
repo_entry_index = path_split.index("local")
461-
loaded_cache_path = sep.join(
462-
path_split[0:repo_entry_index + 2])
463-
if loaded_cache_path != current_cache_path and os.path.exists(
464-
current_cache_path):
465-
new_env[key][i] = val2.replace(
466-
loaded_cache_path, current_cache_path).replace(sep, "/")
473+
if isinstance(val2, str):
474+
# Check if path contains cache directory pattern
475+
normalized_val2 = val2.replace(
476+
'\\', os.sep).replace('/', os.sep)
477+
if os.sep.join(['local', 'cache']) in normalized_val2:
478+
new_env[key][i] = normalize_and_replace_path(val2)
467479

468480
return {'return': 0, 'new_env': new_env}
469481

0 commit comments

Comments
 (0)