You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add comprehensive TensorBlobManager tests and cleanup (#162)
Summary:
## Overview
This PR adds comprehensive test coverage for the `TensorBlobManager` functionality and performs minor cleanup in the test infrastructure.
## Changes
### 1. Test Infrastructure Cleanup
- **Removed unnecessary torch inductor metrics reset** (`tests/test_tritonparse.py:111`)
- Removed `torch._inductor.metrics.reset()` call from the `clear_all_caches()` helper function
- This line was not essential for cache clearing functionality
### 2. New Test: `test_tensor_blob_manager`
Added a comprehensive test case (~280 lines) to validate the TensorBlobManager functionality with four distinct test scenarios:
#### Test 1: Mixed Tensor Sizes with Compression Threshold
- Tests automatic compression based on size threshold (1MB)
- Validates that small tensors (2KB, 400KB) are saved as `.bin` files
- Validates that large tensors (20MB, 400MB) are saved as `.bin.gz` compressed files
- Confirms both `.bin` and `.bin.gz` formats can be loaded correctly
#### Test 2: Deduplication
- Tests tensor deduplication when the same tensor is reused multiple times
- Runs the same kernel 3 times with identical input
- Verifies that blob count is reduced through deduplication (< 6 blobs for 3 launches)
- Ensures at least 1 blob is created for the deduplicated input
#### Test 3: Quota Limit Enforcement
- Tests storage quota mechanism with a 60KB limit
- Verifies first tensor is saved successfully
- Confirms storage is disabled after quota is exceeded
- Validates that no additional blobs are saved once quota is reached
- Resets global variables to prevent test pollution
#### Test 4: Disabled Storage
- Tests that tensor blob storage can be explicitly disabled
- Verifies no blob files are created when `enable_tensor_blob_storage=False`
- Confirms `saved_tensors` directory remains empty
### Test Utilities
The new test includes helper functions:
- `collect_blob_files()`: Collects all `.bin` and `.bin.gz` files from saved_tensors directory
- `count_all_blobs()`: Counts total number of blob files
## Testing Approach
- Uses `unittest.skipUnless` to ensure tests only run when CUDA is available
- Employs temporary directories for isolated test execution
- Includes proper cleanup with `TEST_KEEP_OUTPUT` flag support for debugging
- Synchronizes CUDA operations to ensure accurate testing
## Impact
- ✅ Improves test coverage for tensor blob storage functionality
- ✅ Validates compression, deduplication, and quota mechanisms
- ✅ Ensures backward compatibility with disabled storage mode
- ✅ Minor cleanup improves test infrastructure maintainability
Pull Request resolved: #162
Test Plan:
```bash
% python -m unittest tests.test_tritonparse -v -k test_tensor_blob_manager
test_tensor_blob_manager (tests.test_tritonparse.TestTritonparseCUDA.test_tensor_blob_manager)
Test TensorBlobManager functionality with context manager ...
=== Test 1: Mixed Tensor Sizes with Compression Threshold ===
Found 4 .bin files:
/tmp/tmp4xaavx1u/saved_tensors/00/0074f9a0e0a6cd25693532e59b2dc8be68303dbb29c47d3b80c0572b6185fc571d5061ba1b20aff86bcf77cd3e6e023cb7ef8efda0ef5a53ff5961ef77fb71ba.bin (3625 bytes)
/tmp/tmp4xaavx1u/saved_tensors/0e/0eac7954d5ade855de02ebf13bb0d98c404d3be28ee7e4ac70b7650bbe0a86c70dc6f16ec4f9ec31b0d4a0c0a52e2264925a67ded46e3007f39fb72fba28a789.bin (3625 bytes)
/tmp/tmp4xaavx1u/saved_tensors/18/1840a6ec1ab8e5261aff496068189a3653095143a249c82bb73c2facde311269cf9c2ab27a90090114eca28150189d1f89f51d33702dd3f3a3183beb6ce14a77.bin (411177 bytes)
/tmp/tmp4xaavx1u/saved_tensors/f8/f81de0a3530c8fbe1aabc8aca52f4d6750925ba19180924850ab5310a966a377918b3677614e38697a7ee5298f612b076d57e1cac89bc1add5f67e9dc9d00cea.bin (411177 bytes)
Found 4 .bin.gz files:
/tmp/tmp4xaavx1u/saved_tensors/32/32e064bc2899066269955ea172112f2a3707ca336e508ceba6717449e20d4971a24961947676618614db58f687edf0856f6e2b93dccdbeb63ea5e2bff81cc02a.bin.gz (21168 bytes)
/tmp/tmp4xaavx1u/saved_tensors/bd/bdb593a4c71ad247c128bc9b378ab313cf00c776279234537f0538bca2fd91b4434f9c83e3fdcf6379808564d883d90ea32dbc9186157c77eebb926576a2d7fe.bin.gz (19424577 bytes)
/tmp/tmp4xaavx1u/saved_tensors/36/368214d5a7f553271ed7697d19a1c46c3c588385cfb6832400dc2ad43fe77108679b7c0bc50c71b26252acb0c15652a8a6d4839eb3e921fa328a59203c7a6538.bin.gz (408465 bytes)
/tmp/tmp4xaavx1u/saved_tensors/cd/cda0384d432651a66629e00d8ba726f194f916b83dc44aa7248b146c2dace4917004b09e8de20d668f61d48f0b00294334e144a19c64daf493f4c2a74119cd33.bin.gz (408549 bytes)
✓ Mixed sizes: 4 uncompressed (.bin), 4 compressed (.bin.gz)
✓ Compression effective: largest file compressed to 18.52 MB
✓ Successfully loaded .bin file
✓ Successfully loaded .bin.gz file
✓ Both formats (.bin and .bin.gz) verified
tritonparse log file list: /tmp/tmpnn37863a/log_file_list.json
INFO:tritonparse:Copying parsed logs from /tmp/tmpnn37863a to /tmp/tmpblkbqgii
================================================================================
📁 TRITONPARSE PARSING RESULTS
================================================================================
📂 Parsed files directory: /tmp/tmpblkbqgii
📊 Total files generated: 2
📄 Generated files:
--------------------------------------------------
1. 📝 dedicated_log_triton_trace_findhao__mapped.ndjson.gz (9.3KB)
2. 📝 log_file_list.json (181B)
================================================================================
✅ Parsing completed successfully!
================================================================================
=== Test 2: Deduplication ===
✓ Deduplication working: 4 unique blob(s) for 3 launches (< 6 without dedup)
WARNING:SourceMapping:No output file for kernel hash 5aeee63456fc3e7aa058576d7bece1ab3cd040db7b92ff2e8988536d850a5897, skipping.
tritonparse log file list: /tmp/tmp7g7a2i9q/log_file_list.json
INFO:tritonparse:Copying parsed logs from /tmp/tmp7g7a2i9q to /tmp/tmp4cr79vzr
================================================================================
📁 TRITONPARSE PARSING RESULTS
================================================================================
📂 Parsed files directory: /tmp/tmp4cr79vzr
📊 Total files generated: 1
📄 Generated files:
--------------------------------------------------
1. 📝 log_file_list.json (106B)
================================================================================
✅ Parsing completed successfully!
================================================================================
=== Test 3: Quota Limit ===
WARNING:tritonparse.structured_logging:⚠️ TENSOR BLOB STORAGE DISABLED: Storage quota would be exceeded: 0.00GB > 0.00GB limit
INFO:tritonparse.structured_logging:📊 Final Tensor blob stats: 1 saved (1 total, 0 dedup), 0.00GB compressed (0.00GB uncompressed), compression ratio: 1.00x
Blobs after first kernel launch: 1
Blobs after second kernel launch: 1
✓ Quota enforced: 1 blob(s) saved before quota limit
WARNING:SourceMapping:No output file for kernel hash 5aeee63456fc3e7aa058576d7bece1ab3cd040db7b92ff2e8988536d850a5897, skipping.
tritonparse log file list: /tmp/tmplcl_o1dt/log_file_list.json
INFO:tritonparse:Copying parsed logs from /tmp/tmplcl_o1dt to /tmp/tmpvo1mmy39
================================================================================
📁 TRITONPARSE PARSING RESULTS
================================================================================
📂 Parsed files directory: /tmp/tmpvo1mmy39
📊 Total files generated: 1
📄 Generated files:
--------------------------------------------------
1. 📝 log_file_list.json (106B)
================================================================================
✅ Parsing completed successfully!
================================================================================
✓ Quota limit test passed (storage disabled when quota exceeded)
=== Test 4: Disabled Storage ===
✓ Storage correctly disabled when enable_tensor_blob_storage=False
WARNING:SourceMapping:No output file for kernel hash 5aeee63456fc3e7aa058576d7bece1ab3cd040db7b92ff2e8988536d850a5897, skipping.
tritonparse log file list: /tmp/tmplamlg5c2/log_file_list.json
INFO:tritonparse:Copying parsed logs from /tmp/tmplamlg5c2 to /tmp/tmph824g9g7
================================================================================
📁 TRITONPARSE PARSING RESULTS
================================================================================
📂 Parsed files directory: /tmp/tmph824g9g7
📊 Total files generated: 1
📄 Generated files:
--------------------------------------------------
1. 📝 log_file_list.json (106B)
================================================================================
✅ Parsing completed successfully!
================================================================================
✓ Cleaned up all test output directories
ok
----------------------------------------------------------------------
Ran 1 test in 9.121s
OK
```
Reviewed By: adamomainz
Differential Revision: D84215701
Pulled By: FindHao
fbshipit-source-id: 2d17ac33d6c1c67dca0231f428a524f8e2413e77
0 commit comments