-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add conv2d support for fourierft and other improvements #2794
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
frutiemax92
wants to merge
9
commits into
huggingface:main
Choose a base branch
from
frutiemax92:feature_fourierft_conv2d
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
28b7fd4
Add conv2d support for fourierft
frutiemax92 bf4dce5
FourierFT: add alpha for dynamic n_frequency
frutiemax92 3172bf0
Stick closer to the paper for conv2d and add the norm option in the c…
frutiemax92 7b408d8
Address most of the comments in the review
frutiemax92 8926877
Add some tests for FourierFT conv2d layers
frutiemax92 9cbc72d
Add fourierft_ifft2_norm to the parameters and other fixes
frutiemax92 2b205f3
Make style
frutiemax92 3613607
Add tests for FourierFT
frutiemax92 2f23126
Add alpha and ifft2_norm to the fourierft docstring
frutiemax92 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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |||||
| from __future__ import annotations | ||||||
|
|
||||||
| from dataclasses import dataclass, field | ||||||
| from typing import Optional, Union | ||||||
| from typing import Literal, Optional, Union | ||||||
|
|
||||||
| from peft.config import PeftConfig | ||||||
| from peft.utils import PeftType | ||||||
|
|
@@ -78,6 +78,14 @@ class FourierFTConfig(PeftConfig): | |||||
| init_weights (`bool`): | ||||||
| The initialization of the Fourier weights. Set this to False (the default) if the spectrum are initialized | ||||||
| to a standard normal distribution. Set this to True if the spectrum are initialized to zeros. | ||||||
| alpha: | ||||||
| The alpha value dynamically sets the n_frequency = int(alpha * out_features * in_features) If alpha is set, | ||||||
| the n_frequency and n_frequency_pattern parameters should not be set. | ||||||
| ifft2_norm: | ||||||
| The normalization applied for the ifft2 operation. It has to be either `backward`, `forward` or `ortho`. | ||||||
| See the pytorch documentation for the ifft2 function for more details | ||||||
| (https://docs.pytorch.org/docs/stable/generated/torch.fft.ifft2.html) The default value is `backward`. | ||||||
|
|
||||||
| """ | ||||||
|
|
||||||
| n_frequency: int = field( | ||||||
|
|
@@ -174,6 +182,17 @@ class FourierFTConfig(PeftConfig): | |||||
| ) | ||||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| ifft2_norm: Optional[Literal["backward", "forward", "ortho"]] = field( | ||||||
| default_factory="backward", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| metadata={ | ||||||
| "help": ( | ||||||
| "The normalization applied for the ifft2 operation. " | ||||||
| "It has to be either `backward`, `forward` or `ortho`. See the pytorch documentation for the ifft2 function for more details " | ||||||
| "(https://docs.pytorch.org/docs/stable/generated/torch.fft.ifft2.html) The default value is `backward`." | ||||||
| ) | ||||||
| }, | ||||||
| ) | ||||||
| init_weights: bool = field( | ||||||
| default=False, | ||||||
| metadata={ | ||||||
|
|
@@ -185,6 +204,16 @@ class FourierFTConfig(PeftConfig): | |||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| alpha: float = field( | ||||||
frutiemax92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| default=None, | ||||||
| metadata={ | ||||||
| "help": ( | ||||||
| "The alpha value dynamically sets the n_frequency = int(alpha * out_features * in_features)" | ||||||
| "If alpha is set, the n_frequency and n_frequency_pattern parameters should not be set." | ||||||
| ) | ||||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| def __post_init__(self): | ||||||
| super().__post_init__() | ||||||
| self.peft_type = PeftType.FOURIERFT | ||||||
|
|
@@ -204,3 +233,9 @@ def __post_init__(self): | |||||
| # check for layers_to_transform and layers_pattern | ||||||
| if self.layers_pattern and not self.layers_to_transform: | ||||||
| raise ValueError("When `layers_pattern` is specified, `layers_to_transform` must also be specified. ") | ||||||
|
|
||||||
frutiemax92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| if (self.alpha is not None) and (self.n_frequency != 1000): | ||||||
| raise ValueError("Don't set both alpha and n_frequency, as alpha overrides n_frequency.") | ||||||
|
|
||||||
| if (self.alpha is not None) and (self.n_frequency_pattern != {}): | ||||||
| raise ValueError("Don't set both alpha and n_frequency_pattern, as alpha overrides n_frequency_pattern.") | ||||||
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
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
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.
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.