Created
January 18, 2023 15:10
-
-
Save 0xnurl/0698cd9d4b8a15f4ccafb77eb0430062 to your computer and use it in GitHub Desktop.
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
def get_free_gpu(): | |
max_free = 0 | |
max_idx = 0 | |
rows = ( | |
subprocess.check_output( | |
["nvidia-smi", "--format=csv", "--query-gpu=memory.free"] | |
) | |
.decode("utf-8") | |
.split("\n") | |
) | |
for i, row in enumerate(rows[1:-1]): | |
mb = float(row.rstrip(" [MiB]")) | |
if mb > max_free: | |
max_idx = i | |
max_free = mb | |
return max_idx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment