Timer improvements - #4
ShashankFC wants to merge 2 commits into
Conversation
Entelligence AI Vulnerability ScannerStatus: No security vulnerabilities found Your code passed our comprehensive security analysis. Analyzed 1 files in total |
Review Summary🏷️ Draft Comments (3)
|
WalkthroughThis PR refactors the timer implementation in PyTorch's distributed elastic module to improve timestamp handling and thread management. The primary change replaces Changes
Sequence DiagramThis diagram shows the interactions between components: sequenceDiagram
participant Client as Client Code
participant Expires as expires() Context
participant TimerClient as Timer Client
participant Queue as Request Queue
participant Watchdog as Watchdog Thread
participant Storage as Timer Storage
participant Reaper as Worker Reaper
Note over Watchdog: Watchdog Loop (_run_watchdog)
loop Continuous Monitoring
Watchdog->>Queue: get(batch_size, max_interval)
Queue-->>Watchdog: timer_requests[]
Watchdog->>Storage: register_timers(timer_requests)
Watchdog->>Watchdog: now = datetime.now().timestamp()
Watchdog->>Storage: get_expired_timers(now)
Storage-->>Watchdog: expired_timers by worker_id
loop For each worker with expired timers
Watchdog->>Reaper: reap_worker(worker_id, expired_timers)
Note over Reaper: Process expired timers<br/>for worker
end
end
Note over Client,TimerClient: Countdown Timer Usage
Client->>Expires: with expires(after=10)
activate Expires
Expires->>Expires: scope = caller_file#lineno
Expires->>Expires: expiration = datetime.now().timestamp() + after
Expires->>TimerClient: acquire(scope, expiration)
TimerClient->>Queue: enqueue timer request
Expires->>Client: yield (enter context)
Client->>Client: Execute protected code
Client->>Expires: exit context
Expires->>TimerClient: release(scope)
deactivate Expires
Note over Watchdog: Improved Shutdown Sequence
Client->>Watchdog: stop()
activate Watchdog
Watchdog->>Watchdog: _stop_signaled = True
Watchdog->>Watchdog: join(max_interval * 2)
alt Thread stops in time
Watchdog->>Watchdog: Thread terminated
else Thread still alive
Watchdog->>Watchdog: Log warning: did not stop in time
end
Watchdog->>Watchdog: _watchdog_thread = None
deactivate Watchdog
🔗 Cross-Repository Impact AnalysisEnable automatic detection of breaking changes across your dependent repositories. → Set up now Learn more about Cross-Repository AnalysisWhat It Does
How to Enable
Benefits
Note for WindsurfPlease change the default marketplace provider to the following in the windsurf settings:Marketplace Extension Gallery Service URL: https://marketplace.visualstudio.com/_apis/public/gallery Marketplace Gallery Item URL: https://marketplace.visualstudio.com/items Entelligence.ai can learn from your feedback. Simply add 👍 / 👎 emojis to teach it your preferences. More shortcuts belowEmoji Descriptions:
Interact with the Bot:
Also you can trigger various commands with the bot by doing The current supported commands are
More commands to be added soon. |
EntelligenceAI PR Summary
This PR improves timer implementation reliability and thread management in PyTorch's distributed elastic timer API.
time.time()todatetime.now().timestamp()in_run_watchdog()andexpires()methodsget_expired_timers()docstring to clarify expired timers use strict less-than comparison_max_intervalto_max_interval * 2