-
Notifications
You must be signed in to change notification settings - Fork 42
Add predefined layout oversampling for stochastic mixer #474
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
oleksost
wants to merge
4
commits into
main
Choose a base branch
from
feature/placeemnt_predefined_layout_set
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
4 commits
Select commit
Hold shift + click to select a range
8b674b1
Sample full layouts instead of independent per layer mixer sampling
oleksost bdd37c7
predefined layout set
oleksost 84bf8cf
Merge remote-tracking branch 'origin/main' into feature/placeemnt_preβ¦
oleksost 9f0a724
Merge branch 'main' into feature/placeemnt_predefined_layout_set
jlamypoirier 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,6 +157,21 @@ class StochasticMixerConfig(MixerConfig): | |
| hint=FieldHint.feature, | ||
| ) | ||
|
|
||
| predefined_layouts: list[list[str]] | None = Field( | ||
| default=None, | ||
| desc="List of predefined layouts to oversample. Each layout is a list of mixer names, one per layer. " | ||
| "Mixer names must match keys in the mixers dict.", | ||
| hint=FieldHint.feature, | ||
| ) | ||
|
|
||
| predefined_layout_probability: float = Field( | ||
|
Collaborator
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. Shouldn't this be a list so each layout has its own probability? |
||
| default=0.0, | ||
| desc="Probability of sampling from predefined_layouts instead of using the sampling_strategy. " | ||
| "Must be in [0, 1]. Only used when predefined_layouts is provided.", | ||
| hint=FieldHint.feature, | ||
| valid=check_field(Assert.in_range_incl, 0.0, 1.0), | ||
| ) | ||
|
|
||
| seed_shift: int = Field( | ||
| default=_BIG_PRIMES[11], | ||
| desc="Seed shift for mixer sampling reproducibility.", | ||
|
|
@@ -191,6 +206,23 @@ def _validate(self) -> None: | |
| normalized_values = normalize_probabilities(list(self.sampling_weights.values())) | ||
| self.sampling_weights = dict(zip(self.sampling_weights.keys(), normalized_values)) | ||
|
|
||
| # Validate predefined layouts | ||
| if self.predefined_layouts is not None: | ||
| if len(self.predefined_layouts) == 0: | ||
| raise ValueError("predefined_layouts must be non-empty if provided") | ||
| mixer_names = set(self.mixers.keys()) | ||
| for i, layout in enumerate(self.predefined_layouts): | ||
| unknown = set(layout) - mixer_names | ||
| if unknown: | ||
| raise ValueError( | ||
| f"predefined_layouts[{i}] contains unknown mixer names: {unknown}. " | ||
| f"Valid names: {mixer_names}" | ||
| ) | ||
| if self.predefined_layout_probability <= 0: | ||
| warnings.warn("predefined_layouts provided but predefined_layout_probability is 0") | ||
| elif self.predefined_layout_probability > 0: | ||
| raise ValueError("predefined_layout_probability > 0 but predefined_layouts is not provided") | ||
|
|
||
| @property | ||
| def layer_class(self) -> "type[StochasticMixer]": | ||
| from fast_llm.layers.decoder.stochastic_mixer import StochasticMixer | ||
|
|
||
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.
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.
list[list[str]]withdefault_factory=listwould be enough