MCPcopy Create free account
hub / github.com/pytorch/executorch / pretty_str

Function pretty_str

util/collect_env.py:620–700  ·  view source on GitHub ↗
(envinfo)

Source from the content-addressed store, hash-verified

618
619
620def pretty_str(envinfo): # noqa: C901
621 def replace_nones(dct, replacement="Could not collect"):
622 for key in dct.keys():
623 if dct[key] is not None:
624 continue
625 dct[key] = replacement
626 return dct
627
628 def replace_bools(dct, true="Yes", false="No"):
629 for key in dct.keys():
630 if dct[key] is True:
631 dct[key] = true
632 elif dct[key] is False:
633 dct[key] = false
634 return dct
635
636 def prepend(text, tag="[prepend]"):
637 lines = text.split("\n")
638 updated_lines = [tag + line for line in lines]
639 return "\n".join(updated_lines)
640
641 def replace_if_empty(text, replacement="No relevant packages"):
642 if text is not None and len(text) == 0:
643 return replacement
644 return text
645
646 def maybe_start_on_next_line(string):
647 # If `string` is multiline, prepend a \n to it.
648 if string is not None and len(string.split("\n")) > 1:
649 return "\n{}\n".format(string)
650 return string
651
652 mutable_dict = envinfo._asdict()
653
654 # If nvidia_gpu_models is multiline, start on the next line
655 mutable_dict["nvidia_gpu_models"] = maybe_start_on_next_line(
656 envinfo.nvidia_gpu_models
657 )
658
659 # If the machine doesn't have CUDA, report some fields as 'No CUDA'
660 dynamic_cuda_fields = [
661 "cuda_runtime_version",
662 "nvidia_gpu_models",
663 "nvidia_driver_version",
664 ]
665 all_cuda_fields = dynamic_cuda_fields + ["cudnn_version"]
666 all_dynamic_cuda_fields_missing = all(
667 mutable_dict[field] is None for field in dynamic_cuda_fields
668 )
669 if (
670 TORCH_AVAILABLE
671 and not torch.cuda.is_available()
672 and all_dynamic_cuda_fields_missing
673 ):
674 for field in all_cuda_fields:
675 mutable_dict[field] = "No CUDA"
676 if envinfo.cuda_compiled_version is None:
677 mutable_dict["cuda_compiled_version"] = "None"

Callers 1

get_pretty_env_infoFunction · 0.85

Calls 6

maybe_start_on_next_lineFunction · 0.85
replace_boolsFunction · 0.85
replace_nonesFunction · 0.85
replace_if_emptyFunction · 0.85
prependFunction · 0.85
is_availableMethod · 0.80

Tested by

no test coverage detected