-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[MISC] Add benchmark test memory monitoring #1981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hughperkins
wants to merge
7
commits into
Genesis-Embodied-AI:main
Choose a base branch
from
hughperkins:hp/add-mem-monitoring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−1
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d40ca1f
renaem tsets on the clsuter, for memory tracking
hughperkins 3b10ba4
Merge remote-tracking branch 'origin/main' into hp/rename-tests-on-cl…
hughperkins 58797b1
ps name has no spaes
hughperkins effb0a0
add monitor test mem
hughperkins b0d5a60
add memory monitoring
hughperkins fa44c09
upload resutls
hughperkins 3cef25b
precommit
hughperkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| from collections import defaultdict | ||
| import csv | ||
| import subprocess | ||
| import time | ||
| import argparse | ||
|
|
||
|
|
||
| def grep(contents: list[str], target): | ||
| return [l for l in contents if target in l] | ||
|
|
||
|
|
||
| def get_cuda_usage() -> dict[int, int]: | ||
| output = subprocess.check_output(["nvidia-smi"]).decode("utf-8") | ||
| section = 0 | ||
| subsec = 0 | ||
| res = {} | ||
| for line in output.split("\n"): | ||
| if line.startswith("|============"): | ||
| section += 1 | ||
| subsec = 0 | ||
| continue | ||
| if line.startswith("+-------"): | ||
| subsec += 1 | ||
| continue | ||
| if section == 2 and subsec == 0: | ||
| if "No running processes" in line: | ||
| continue | ||
| split_line = line.split() | ||
| pid = int(split_line[4]) | ||
| mem = int(split_line[-2].split("MiB")[0]) | ||
| res[pid] = mem | ||
| return res | ||
|
|
||
|
|
||
| def get_test_name_by_pid() -> dict[int, str]: | ||
| ps_ef = subprocess.check_output(["ps", "-ef"]).decode("utf-8").split("\n") | ||
| test_lines = grep(ps_ef, "pytest-xdist") | ||
| tests = [line.partition("::")[2] for line in test_lines] | ||
| psids = [int(line.split()[1]) for line in test_lines] | ||
| test_by_psid = {psid: test for test, psid in zip(tests, psids) if test.strip() != ""} | ||
| return test_by_psid | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--out-csv-filepath", type=str, required=True) | ||
| args = parser.parse_args() | ||
|
|
||
| max_mem_by_test = defaultdict(int) | ||
|
|
||
| f = open(args.out_csv_filepath, "w") | ||
| dict_writer = csv.DictWriter(f, fieldnames=["test", "max_mem_mb"]) | ||
| dict_writer.writeheader() | ||
| old_mem_by_test = {} | ||
| num_results_written = 0 | ||
| disp = False | ||
| while True: | ||
| mem_by_pid = get_cuda_usage() | ||
| test_by_psid = get_test_name_by_pid() | ||
| num_tests = len(test_by_psid) | ||
| _mem_by_test = {} | ||
| for psid, test in test_by_psid.items(): | ||
| if psid not in mem_by_pid: | ||
| continue | ||
| if test.strip() == "": | ||
| continue | ||
| _mem = mem_by_pid[psid] | ||
| _mem_by_test[test] = _mem | ||
| for test, _mem in _mem_by_test.items(): | ||
| max_mem_by_test[test] = max(_mem, max_mem_by_test[test]) | ||
| for _test, _mem in old_mem_by_test.items(): | ||
| if _test not in _mem_by_test: | ||
| dict_writer.writerow({"test": _test, "max_mem_mb": max_mem_by_test[_test]}) | ||
| f.flush() | ||
| num_results_written += 1 | ||
| spinny = "x" if disp else "+" | ||
| print( | ||
| num_tests, | ||
| "tests running, of which", | ||
| len(_mem_by_test), | ||
| "on gpu. Num results written: ", | ||
| num_results_written, | ||
| "[updating]", | ||
| " ", | ||
| end="\r", | ||
| flush=True, | ||
| ) | ||
| old_mem_by_test = _mem_by_test | ||
| disp = not disp | ||
| time.sleep(1.0) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.