-
Notifications
You must be signed in to change notification settings - Fork 1
TorchWatcher: Track layer-wise metrics from PyTorch models to Neptune #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
LeoRoccoBreedt
wants to merge
105
commits into
main
Choose a base branch
from
lb/example_torchwatcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…en and project name
…calculate gradient norms for batch (step) rather than epoch
…debugging when building LLM's
…sses using the data loader
- package to initialize hooks for Pytorch models, replacing theHookManager class - add readme.md for using the package - update the degbugging pytorch example to use the new package
…rs as well as allowing a user to specify which layers to track
…etrics to track rather than named values
…ning loop. - more control on namespace logged during training
These need to be updated the the final branch when merged
…ging_model_training
Reviewer's GuideThis PR introduces a PyTorch layer-wise monitoring integration for Neptune by implementing a standalone TorchWatcher utility, accompanied by tutorial and how-to notebooks, documentation, example scripts, and updates to the CI workflow to execute these new assets. Sequence Diagram for TorchWatcher's watch() methodsequenceDiagram
participant TL as Training Loop
participant TW as TorchWatcher
participant HM as HookManager
participant PM as PyTorchModel (nn.Module)
participant NR as NeptuneRun
TL->>TW: watch(step, track_activations_flag, track_gradients_flag, track_parameters_flag)
TW->>TW: Clear internal metrics buffer
opt track_activations_flag is true
TW->>HM: get_activations()
activate HM
HM-->>TW: activation_tensors
deactivate HM
TW->>TW: Process activation_tensors (compute stats, add to buffer)
end
opt track_gradients_flag is true
TW->>HM: get_gradients()
activate HM
HM-->>TW: gradient_tensors
deactivate HM
TW->>TW: Process gradient_tensors (compute stats, add to buffer)
end
opt track_parameters_flag is true
TW->>PM: Access parameter gradients (param.grad)
activate PM
PM-->>TW: parameter_gradient_tensors
deactivate PM
TW->>TW: Process parameter_gradient_tensors (compute stats, add to buffer)
end
TW->>NR: log_metrics(buffered_metrics, step)
TW->>HM: clear() (clear stored activations/gradients in HookManager)
Class Diagram for TorchWatcher and HookManagerclassDiagram
class TorchWatcher {
-model: nn.Module
-run: NeptuneRun
-hm: HookManager
-debug_metrics: Dict
-base_namespace: str
-tensor_stats: Dict
+__init__(model, run, track_layers, tensor_stats, base_namespace)
-_safe_tensor_stats(tensor) Dict
-_track_metric(metric_type, data, namespace)
+track_activations(namespace)
+track_gradients(namespace)
+track_parameters(namespace)
+watch(step, track_gradients, track_parameters, track_activations, namespace)
}
class HookManager {
-model: nn.Module
-hooks: List
-activations: Dict
-gradients: Dict
-track_layers: List
+__init__(model, track_layers)
+save_activation(name) Callable
+save_gradient(name) Callable
+register_hooks(track_activations, track_gradients)
+remove_hooks()
+clear()
+get_activations() Dict
+get_gradients() Dict
+__del__()
}
class NeptuneRun {
<<Service Interface>>
+log_metrics(data, step)
}
class nn.Module {
<<PyTorch Library>>
+named_parameters()
+register_forward_hook()
+register_full_backward_hook()
}
TorchWatcher "1" *-- "1" HookManager : creates & owns
TorchWatcher ..> nn.Module : uses
TorchWatcher ..> NeptuneRun : logs to
HookManager ..> nn.Module : registers hooks on & uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Include a summary of the changes and the related issue.
Related to: <ClickUp/JIRA task name>
Any expected test failures?
Add a
[X]
to relevant checklist items❔ This change
✔️ Pre-merge checklist
🧪 Test Configuration
Summary by Sourcery
Add a new PyTorch monitoring integration by introducing the TorchWatcher package with supporting notebooks, example script, and documentation, and update CI to test the new notebooks.
New Features:
CI:
Documentation: