Skip to content

Commit

Permalink
[Minor] print_directory_tree returns a string
Browse files Browse the repository at this point in the history
ghstack-source-id: d57f19dd8efcef06676fca40a4d6f95367ff1d55
Pull Request resolved: #1086
  • Loading branch information
vmoens committed Nov 13, 2024
1 parent 3cb5855 commit 2b19ef1
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tensordict/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,7 @@ def _is_json_serializable(item):
return isinstance(item, (str, int, float, bool)) or item is None


def print_directory_tree(path, indent="", display_metadata=True):
def print_directory_tree(path, indent="", display_metadata=True) -> str:
"""Prints the directory tree starting from the specified path.
Args:
Expand All @@ -2149,7 +2149,11 @@ def print_directory_tree(path, indent="", display_metadata=True):
display_metadata (bool): if ``True``, metadata of the dir will be
displayed too.
Returns:
the string printed with the logger.
"""
string = []
if display_metadata:

def get_directory_size(path="."):
Expand All @@ -2171,17 +2175,23 @@ def format_size(size):

total_size_bytes = get_directory_size(path)
formatted_size = format_size(total_size_bytes)
logger.info(f"Directory size: {formatted_size}")
string.append(f"Directory size: {formatted_size}")
logger.info(string[-1])

if os.path.isdir(path):
logger.info(indent + os.path.basename(path) + "/")
string.append(indent + os.path.basename(path) + "/")
logger.info(string[-1])
indent += " "
for item in os.listdir(path):
print_directory_tree(
os.path.join(path, item), indent=indent, display_metadata=False
string.append(
print_directory_tree(
os.path.join(path, item), indent=indent, display_metadata=False
)
)
else:
logger.info(indent + os.path.basename(path))
string.append(indent + os.path.basename(path))
logger.info(string[-1])
return "\n".join(string)


def isin(
Expand Down

2 comments on commit 2b19ef1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'CPU Benchmark Results'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 2b19ef1 Previous: 3cb5855 Ratio
benchmarks/common/memmap_benchmarks_test.py::test_serialize_weights_pickle 1.2001728138436225 iter/sec (stddev: 0.36544257441193956) 2.5049451550122575 iter/sec (stddev: 0.06306802358649491) 2.09

This comment was automatically generated by workflow using github-action-benchmark.

CC: @vmoens

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'GPU Benchmark Results'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 2b19ef1 Previous: 3cb5855 Ratio
benchmarks/common/common_ops_test.py::test_membership_stacked_nested_last 128646.71163102194 iter/sec (stddev: 5.684380654436472e-7) 348271.9349327994 iter/sec (stddev: 3.4638149985093136e-7) 2.71
benchmarks/common/common_ops_test.py::test_membership_stacked_nested_leaf_last 128003.88312994676 iter/sec (stddev: 5.485283337949752e-7) 355551.0320966726 iter/sec (stddev: 3.335797218531163e-7) 2.78

This comment was automatically generated by workflow using github-action-benchmark.

CC: @vmoens

Please sign in to comment.