MCPcopy Create free account
hub / github.com/pytorch/pytorch / write

Function write

torch/_inductor/codecache.py:357–373  ·  view source on GitHub ↗
(
    content: Union[str, bytes],
    extension: str,
    extra: str = "",
    hash_type: str = "code",
    specified_dir: str = "",
)

Source from the content-addressed store, hash-verified

355
356
357def write(
358 content: Union[str, bytes],
359 extension: str,
360 extra: str = "",
361 hash_type: str = "code",
362 specified_dir: str = "",
363) -> Tuple[str, str]:
364 # use striped content to compute hash so we don't end up with different
365 # hashes just because the content begins/ends with differnet number of
366 # spaces.
367 key: str = get_hash(content.strip(), extra, hash_type)
368 basename, subdir, path = get_path(key, extension, specified_dir)
369 if not os.path.exists(subdir):
370 os.makedirs(subdir, exist_ok=True)
371 if not os.path.exists(path):
372 write_atomic(path, content)
373 return basename, path
374
375
376def write_atomic(path: str, content: Union[str, bytes]) -> None:

Callers 9

__bool__Method · 0.70
setMethod · 0.70
compileMethod · 0.70
cpp_prefix_pathFunction · 0.70
loadMethod · 0.70
writeMethod · 0.70
loadMethod · 0.70
writeMethod · 0.70
save_globalMethod · 0.50

Calls 5

get_hashFunction · 0.85
get_pathFunction · 0.85
write_atomicFunction · 0.85
stripMethod · 0.80
makedirsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…