-
Notifications
You must be signed in to change notification settings - Fork 328
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
[Feature] Extract primers from modules that contain RNNs #2127
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
221756f
get_primers_from_module
albertbou92 3cc8ea8
format
albertbou92 918a1b9
format
albertbou92 320d873
format
albertbou92 96ad080
Merge remote-tracking branch 'origin/main' into extract_module_primers
vmoens 35d7e56
fix import and header
albertbou92 240d5bd
add to doc
albertbou92 232dbb4
add example
albertbou92 97696d3
add cross refs
albertbou92 0937e79
Apply suggestions from code review
vmoens f48eb0c
add test
albertbou92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
get_primers_from_module
- Loading branch information
commit 221756f3c30a17722d050f8b922ba65ecd30a2e2
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import warnings | ||
albertbou92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
from torchrl.envs import Compose | ||
albertbou92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def get_primers_from_module(module): | ||
"""Get all tensordict primers from all submodules of a module.""" | ||
primers = [] | ||
|
||
def make_primers(submodule): | ||
if hasattr(submodule, "make_tensordict_primer"): | ||
primers.append(submodule.make_tensordict_primer()) | ||
|
||
module.apply(make_primers) | ||
if not primers: | ||
raise warnings.warn("No primers found in the module.") | ||
vmoens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elif len(primers) == 1: | ||
return primers[0] | ||
else: | ||
return Compose(primers) | ||
albertbou92 marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-commit reformatted this