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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ At its core, MLCFlow relies on a single powerful automation, the Script, which i
## 🀝 Contributing
We welcome contributions from the community! To contribute:
1. Submit pull requests (PRs) to the **`dev`** branch.
2. Review our [CONTRIBUTORS.md](here) for guidelines and best practices.
2. See [here](CONTRIBUTORS.md) for guidelines and best practices on contribution.
3. Explore more about MLPerf Inference automation in the official [MLPerf Inference Documentation](https://docs.mlcommons.org/inference/).

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

We appreciate their contributions and sponsorship!
Expand Down
66 changes: 39 additions & 27 deletions automation/script/cache_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,40 +430,52 @@ def find_cached_script(i):

def fix_cache_paths(cached_path, env):

current_cache_path = cached_path
current_cache_path = os.path.normpath(cached_path)

new_env = env # just a reference

def normalize_and_replace_path(path_str):
"""Helper to normalize and replace cache paths in a string."""
# Normalize the path to use the current OS separators
normalized = os.path.normpath(path_str)

# Check if path contains local/cache or local\cache pattern
path_parts = normalized.split(os.sep)

try:
local_idx = path_parts.index("local")
if local_idx + \
1 < len(path_parts) and path_parts[local_idx + 1] == "cache":
# Extract the loaded cache path (up to and including "cache")
loaded_cache_path = os.sep.join(path_parts[:local_idx + 2])
loaded_cache_path_norm = os.path.normpath(loaded_cache_path)

if loaded_cache_path_norm != current_cache_path and os.path.exists(
current_cache_path):
# Replace old cache path with current cache path
return normalized.replace(
loaded_cache_path_norm, current_cache_path)
except (ValueError, IndexError):
# "local" not in path or malformed path
pass

return normalized

for key, val in new_env.items():
# Check for a path separator in a string and determine the
# separator
if isinstance(val, str) and any(sep in val for sep in [
"/local/cache/", "\\local\\cache\\"]):
sep = "/" if "/local/cache/" in val else "\\"

path_split = val.split(sep)
repo_entry_index = path_split.index("local")
loaded_cache_path = sep.join(
path_split[0:repo_entry_index + 2])
if loaded_cache_path != current_cache_path and os.path.exists(
current_cache_path):
new_env[key] = val.replace(
loaded_cache_path, current_cache_path).replace(sep, "/")
if isinstance(val, str):
# Check if path contains cache directory pattern
normalized_val = val.replace('\\', os.sep).replace('/', os.sep)
if os.sep.join(['local', 'cache']) in normalized_val:
new_env[key] = normalize_and_replace_path(val)

elif isinstance(val, list):
for i, val2 in enumerate(val):
if isinstance(val2, str) and any(sep in val2 for sep in [
"/local/cache/", "\\local\\cache\\"]):
sep = "/" if "/local/cache/" in val2 else "\\"

path_split = val2.split(sep)
repo_entry_index = path_split.index("local")
loaded_cache_path = sep.join(
path_split[0:repo_entry_index + 2])
if loaded_cache_path != current_cache_path and os.path.exists(
current_cache_path):
new_env[key][i] = val2.replace(
loaded_cache_path, current_cache_path).replace(sep, "/")
if isinstance(val2, str):
# Check if path contains cache directory pattern
normalized_val2 = val2.replace(
'\\', os.sep).replace('/', os.sep)
if os.sep.join(['local', 'cache']) in normalized_val2:
new_env[key][i] = normalize_and_replace_path(val2)

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

Expand Down
Loading