-
Notifications
You must be signed in to change notification settings - Fork 541
Optim-wip: Composable loss improvements #828
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
Open
ProGamerGov
wants to merge
10
commits into
meta-pytorch:optim-wip
Choose a base branch
from
ProGamerGov:optim-wip-composable-loss-improvements
base: optim-wip
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.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c96cd72
Composable loss improvements
ProGamerGov b7e2f35
Set minimum torch version for positive CompositeLoss test
ProGamerGov da0c472
Fix import
ProGamerGov ac5bc74
Improvements to CompositeLoss
ProGamerGov b25f927
Fix Mypy type hints
ProGamerGov 26d7007
Fix flake8 error
ProGamerGov 3a41426
Add batch_index support for Diversity & Alignment
ProGamerGov ce897d3
Improvements to custom_composable_op
ProGamerGov 1ecf1c0
Merge branch 'optim-wip' into optim-wip-composable-loss-improvements
ProGamerGov 3438cf1
Support any number of target batch dimensions
ProGamerGov 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
There are no files selected for viewing
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
if the
target
can beList[nn.Module]
, many losses below cannot directly use it as dict keytargets_to_values[self.target]
. Did I miss anything?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.
@aobo-y Losses like
ActivationInterpolation
have multiple targets (Faceted loss as well in an upcoming PR), butBaseLoss
works off using a singletarget
variable.The
BaseLoss
class is called in the__init__
functions of loss classes like so:The loss class itself will indicate via
target: List[nn.Module]
type hint that multiple targets are supported / required, or it is handled things internally by passing the targets as a list toBaseLoss
like inActivationInterpolation
.The
ActivationInterpolation
loss class can be found here: https://github.com/ProGamerGov/captum/blob/optim-wip-composable-loss-improvements/captum/optim/_core/loss.py#L506There 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.
Sure, but cases like
DeepDream
and some others directly inherits BaseLoss's init definition, wheretarget
can be a list while actually it should not https://github.com/ProGamerGov/captum/blob/optim-wip-composable-loss-improvements/captum/optim/_core/loss.py#L393-L407If these losses have different assumptions of what their targets should be, why do we abstract the
target
into the base class. The base classBaseLoss
does not needtarget
anyway. Each class can define their owntarget
in__init__
. Or we can have 2 other intermediate abstract classesSingleTargetLoss
MultiTargetsLoss
But anyway, this is just for discussion. It has nth related to this PR. We can leave it to future updates if needed.
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.
Oh, yeah I see what you mean now. In the original code, I think that Ludwig had
SingleTargetObjective
&MultiObjective
for handling these cases: https://github.com/ludwigschubert/captum/blob/f1fd0729dece59564a7c10b7b397617d8a09a247/captum/optim/optim/objectives.py#L108It'd probably be best to leave this to a future PR if decide on the changes