Skip to content

Commit 0bec52d

Browse files
committed
Refactor logging system and improve device redirection
- Optimized logging with a new TDLogger module - Simplified logging interface by removing verbosity levels - Enhanced log message filtering and context tracking - Improved device redirection and stream/event handling - Updated README, tests, and demo scripts to reflect changes - Bumped version to 0.0.2 to reflect significant improvements
1 parent 6a51b00 commit 0bec52d

31 files changed

+1981
-509
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,5 @@ $RECYCLE.BIN/
296296
test_projects/cuda-pytorch-template
297297
.project-planning/
298298
test_projects/
299+
backup/
300+
*.bak*

CHANGELOG.md

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
# CHANGELOG
22

3+
## 2025-03-08 - 0.0.3
4+
5+
### Logger Improvements
6+
- Optimized the `_logged_messages` collection by replacing the set with a fixed-size deque
7+
- This change improves memory management by automatically removing oldest entries when the collection is full
8+
- Eliminates the need to clear the entire collection, providing more consistent duplicate prevention
9+
- Consolidated duplicate code by extracting common logic into helper functions:
10+
- Added `is_test_environment()` to determine if running in a test environment
11+
- Added `is_internal_frame()` to identify frames that should be skipped
12+
- Added `should_skip_message()` to centralize message filtering logic
13+
- Added `is_setup_or_init()` to identify setup and initialization functions
14+
- Improved caller identification to ensure log messages show the actual caller
15+
- Enhanced message filtering to ensure important redirection messages are always logged
16+
17+
### Test Framework Improvements
18+
- Created a robust test framework with a `PrefixedTestCase` class in `test_utils.py`
19+
- Fixed test discovery and execution to ensure consistent environment variables
20+
- Improved logging during tests with better context and error handling
21+
- Enhanced expected output file management for more reliable test results
22+
- Fixed issues with program name consistency in log messages during tests
23+
24+
## 2025-03-03 - 0.0.2
25+
26+
### Logging System Improvements
27+
- Modularized logging: Moved logging functionality into its own module (`TDLogger.py`)
28+
- Simplified logging interface:
29+
- Removed verbosity levels (LOG_VERBOSITY) in favor of a simpler on/off approach
30+
- Eliminated different message classes (warning, info, error) for a more streamlined logging experience
31+
- Consolidated all logging to use a single `log_message` function as the primary entry point
32+
- Removed redundant `log` function since the project hasn't been publicly released yet
33+
- Improved caller tracking for more accurate log messages
34+
- Optimized memory usage by limiting the size of the logged messages cache
35+
- Enhanced test suite with expected output validation
36+
337
## 2024-12-30 - 0.0.1
438

539
- Added note regarding building NumPy for Apple silicon.

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ device = torch.device('cuda') # This will be redirected based on available hard
141141
- If MPS is requested but not available, it will redirect to CUDA if available.
142142
- If neither is available, it will default to CPU.
143143
- **Logging**: The module outputs log messages indicating how calls are intercepted and handled. These messages include the caller's filename, function name, and line number.
144-
- **Verbosity Control**: You can control the verbosity of logging by setting the `TORCHDEVICE_LOG_VERBOSITY` environment variable (0=minimal, 1=verbose, 2=debug).
145144
- **Log File**: You can direct logs to a file by setting the `TORCHDEVICE_LOG_FILE` environment variable.
146145
- **Unsupported Functions**: Functions that are not supported on the current hardware are stubbed and will log a warning but allow execution to continue.
147146
- **Stream and Event Support**: CUDA streams and events are fully supported on MPS devices, allowing for asynchronous operations and event timing.

TODO.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# TorchDevice Project TODO List
2+
3+
## Logger Improvements
4+
5+
- **Simplify the Frame Inspection Logic**
6+
- Review the current implementation of `get_caller_info()`
7+
- Identify opportunities for simplification
8+
- Implement a more direct approach to find the caller frame
9+
10+
- **Implement Caching for Performance**
11+
- Identify functions that are called frequently with the same arguments
12+
- Add caching for these functions (e.g., using functools.lru_cache)
13+
- Measure the performance impact of these changes
14+
15+
- **Use Context Managers for Temporary State**
16+
- Identify operations that temporarily modify state
17+
- Implement context managers for these operations
18+
- Ensure proper cleanup even in case of exceptions

0 commit comments

Comments
 (0)