Commit fa06e41
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:1 parent 7a9de8f commit fa06e41
1 file changed
+275
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
| |||
1168 | 1167 | | |
1169 | 1168 | | |
1170 | 1169 | | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
1171 | 1445 | | |
1172 | 1446 | | |
1173 | 1447 | | |
0 commit comments