MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / find_replace_str

Function find_replace_str

deepspeed/autotuning/utils.py:41–56  ·  view source on GitHub ↗
(value, replace_dict)

Source from the content-addressed store, hash-verified

39
40
41def find_replace_str(value, replace_dict):
42 if not isinstance(value, str):
43 return str(value)
44
45 matches = re.findall(r"\$[\w]+", value)
46 for var in matches:
47 var_key = var.replace("$", "").lower()
48 if var_key == "nvme_path":
49 continue
50 assert var_key in replace_dict, f"unknown var key: {var_key}, in {replace_dict}"
51 if isinstance(replace_dict[var_key], str):
52 value = value.replace(var, replace_dict[var_key])
53 else:
54 assert len(matches) == 1, "unable to replace multiple non-string matches"
55 value = replace_dict[var_key]
56 return value
57
58
59def find_replace(target, replace_dict):

Callers 1

find_replaceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected