Skip to content

Commit

Permalink
NOCOMMIT: log peak mem usage and swapouts to debug test-llava-runner
Browse files Browse the repository at this point in the history
Attempting to test my theory that the timestamp gaps in #8180 are caused by swapping.

ghstack-source-id: 7582788e769145f75800de5eee0d024c0966a98a
ghstack-comment-id: 2634969596
Pull Request resolved: #8192
  • Loading branch information
swolchok committed Feb 6, 2025
1 parent 8ec08f9 commit f8c55cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 10 additions & 2 deletions examples/models/llama/source_transformation/quantized_kv_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,15 @@ def replace_kv_cache_with_quantized_kv_cache(module):
torch.ops.load_library(libs[0])
op = torch.ops.quantized_decomposed.quantize_per_token.out
assert op is not None
import gc
import resource

# This is needed to ensure that custom ops are registered
from executorch.extension.llm.custom_ops import custom_ops # noqa: F401

rusage = resource.getrusage(resource.RUSAGE_SELF)
logging.warning(
"Replacing KVCache with QuantizedKVCache. This modifies the model in place."
f"Replacing KVCache with QuantizedKVCache. This modifies the model in place. (HACK: rusage: {rusage} gc stats: {gc.get_stats()})"
)
for name, child in module.named_children():
if isinstance(child, KVCache) or isinstance(child, CustomKVCache):
Expand Down Expand Up @@ -270,8 +274,12 @@ def replace_kv_cache_with_custom_kv_cache(module):
This is because the custom op treats second dim as sequence dim.
Future work: support [B, H, S, D]
"""
import gc
import resource

rusage = resource.getrusage(resource.RUSAGE_SELF)
logging.warning(
"Replacing KVCache with CustomKVCache. This modifies the model in place."
f"Replacing KVCache with CustomKVCache. This modifies the model in place. (HACK: rusage: {rusage} gc stats: {gc.get_stats()})"
)
for name, child in module.named_children():
if isinstance(child, KVCache):
Expand Down
2 changes: 2 additions & 0 deletions examples/models/llava/test/test_llava.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

import gc
gc.set_debug(gc.DEBUG_STATS | gc.DEBUG_COLLECTABLE)

class TestLlava(unittest.TestCase):
def setUp(self):
Expand Down
8 changes: 7 additions & 1 deletion extension/llm/export/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ def source_transform(

if self.verbose:
logging.info(f"Applied source transforms: {self.applied_source_transforms}")
logging.info(f"Model after source transforms: {self.model}")
import gc
import resource

rusage = resource.getrusage(resource.RUSAGE_SELF)
logging.info(
f"Model after source transforms: {self.model} (HACK: rusage: {rusage} gc_stats: {gc.get_stats()})"
)
return self

def _get_dynamic_shape(self) -> Any:
Expand Down

0 comments on commit f8c55cb

Please sign in to comment.