Skip to content

Commit 3e9c47d

Browse files
authored
Update code and README (#122)
1 parent bd37672 commit 3e9c47d

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

experiments/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ For GPU,
5555
- $ pip install https://download.pytorch.org/whl/nightly/cu121/torch-2.2.0.dev20231117%2Bcu121-cp310-cp310-linux_x86_64.whl
5656
- $ pip install https://download.pytorch.org/whl/nightly/cu121/torchvision-0.17.0.dev20231117%2Bcu121-cp310-cp310-linux_x86_64.whl
5757
For CPU,
58-
- $ pip install https://download.pytorch.org/whl/nightly/cpu/torch-2.4.0.dev20240509%2Bcpu-cp310-cp310-linux_x86_64.whl
59-
- $ pip install https://download.pytorch.org/whl/nightly/cpu/torchvision-0.19.0.dev20240509%2Bcpu-cp310-cp310-linux_x86_64.whl
60-
- $ pip install triton
58+
- $ pip install https://download.pytorch.org/whl/nightly/cpu/torch-2.4.0.dev20240530%2Bcpu-cp310-cp310-linux_x86_64.whl
59+
- $ pip install https://download.pytorch.org/whl/nightly/cpu/torchvision-0.19.0.dev20240530%2Bcpu-cp310-cp310-linux_x86_64.whl
60+
- $ install triton based on https://github.com/triton-lang/triton?tab=readme-ov-file#quick-installation
6161
6262
$ git clone https://github.com/cpuhrsch/segment-anything.git
6363
$ cd segment-anything

experiments/eval_combo.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import math
77
import segment_anything_fast
88
import time
9+
import resource
910

1011
torch._dynamo.config.cache_size_limit = 50000
1112

@@ -257,7 +258,10 @@ def profile_top_runner(fn, *args, **kwargs):
257258
torch.profiler.ProfilerActivity.CUDA],
258259
record_shapes=True) as prof:
259260
result = fn(*args, **kwargs)
260-
print(prof.key_averages().table(sort_by="self_cuda_time_total", row_limit=-1))
261+
if torch.cuda.is_available():
262+
print(prof.key_averages().table(sort_by="self_cuda_time_total", row_limit=-1))
263+
else:
264+
print(prof.key_averages().table(sort_by="self_cpu_time_total", row_limit=-1))
261265
return result
262266

263267

@@ -444,15 +448,22 @@ def run(
444448
batch_ms_batch_size = (avg_ms_per_img * num_images) / num_batches / batch_size
445449

446450
mIoU = calculate_miou(results, mask_debug_out_dir, True, cat_id_to_cat)
447-
max_memory_allocated_bytes = torch.cuda.max_memory_allocated()
448-
_, total_memory = torch.cuda.mem_get_info()
449-
max_memory_allocated_percentage = int(100 * (max_memory_allocated_bytes / total_memory))
450-
max_memory_allocated_bytes = max_memory_allocated_bytes >> 20
451+
if torch.cuda.is_available():
452+
max_memory_allocated_bytes = torch.cuda.max_memory_allocated()
453+
_, total_memory = torch.cuda.mem_get_info()
454+
max_memory_allocated_percentage = int(100 * (max_memory_allocated_bytes / total_memory))
455+
max_memory_allocated_bytes = max_memory_allocated_bytes >> 20
456+
else:
457+
import psutil
458+
total_memory = psutil.virtual_memory().total
459+
max_memory_allocated_bytes = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
460+
max_memory_allocated_percentage = int(100 * (max_memory_allocated_bytes / (total_memory >> 10)))
461+
max_memory_allocated_bytes = max_memory_allocated_bytes >> 10
451462

452463
if print_header:
453-
print(",".join(["sam_model_type", "batch_size", "memory(MiB)", "memory(%)", "img_s(avg)", "batch_ms(avg)/batch_size", "mIoU", "use_compile",
464+
print(",".join(["device", "sam_model_type", "batch_size", "memory(MiB)", "memory(%)", "img_s(avg)", "batch_ms(avg)/batch_size", "mIoU", "use_compile",
454465
"use_half", "compress", "epilogue_fusion_first", "use_compile_decoder", "use_nested_tensor", "use_rel_pos", "pad_input_image_batch", "num_workers", "num_batches", "num_images", "profile_path", "memory_path"]))
455-
print(",".join(map(str, [sam_model_type, batch_size, max_memory_allocated_bytes, max_memory_allocated_percentage, img_s, batch_ms_batch_size, mIoU, use_compile,
466+
print(",".join(map(str, [device, sam_model_type, batch_size, max_memory_allocated_bytes, max_memory_allocated_percentage, img_s, batch_ms_batch_size, mIoU, use_compile,
456467
use_half, compress, epilogue_fusion_first, use_compile_decoder, use_nested_tensor, use_rel_pos, pad_input_image_batch, num_workers, num_batches, num_images, profile_path, memory_path])))
457468

458469

0 commit comments

Comments
 (0)