-
Notifications
You must be signed in to change notification settings - Fork 640
feat(passthrough): Introduce noise injection #642
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,27 @@ def execute(self, tensors: Dict[ModelReference, torch.Tensor]) -> torch.Tensor: | |
| if scale is not None: | ||
| tensor = tensor * scale | ||
|
|
||
| noise_scale = self.tensor_parameters[model].data.get("noise_scale", None) | ||
| if noise_scale is not None and noise_scale != 0.0: | ||
| noise_seed = self.tensor_parameters[model].data.get("noise_seed", 42) | ||
| noise_generator = torch.Generator() | ||
| if noise_seed is not None: | ||
| noise_generator = noise_generator.manual_seed(int(noise_seed)) | ||
| print("applying noise_seed") | ||
|
|
||
| print(f"Noise Generator Seed: {noise_generator.initial_seed()}") | ||
| random_tensor = torch.empty_like(tensor).normal_(generator=noise_generator) | ||
| noisy_tensor = random_tensor * noise_scale | ||
|
|
||
| noise_variance = self.tensor_parameters[model].data.get("noise_variance", False) | ||
| if noise_variance is not None and noise_variance != 0.0: | ||
| noisy_tensor = noisy_tensor * (tensor.std() * noise_variance) | ||
| print("applying noise_variance") | ||
|
|
||
| tensor = tensor + noisy_tensor | ||
|
|
||
| print(f"noise_scale={noise_scale}, noise_seed={noise_seed}, noise_variance={noise_variance}") | ||
|
|
||
| return tensor | ||
|
|
||
| def group_label(self) -> Optional[str]: | ||
|
|
@@ -46,7 +67,12 @@ def pretty_name(self) -> Optional[str]: | |
| return "Passthrough" | ||
|
|
||
| def tensor_parameters(self) -> List[ConfigParameterDef]: | ||
| return [ConfigParameterDef(name="scale", required=False, default_value=None)] | ||
| return [ | ||
| ConfigParameterDef(name="scale", required=False, default_value=None), | ||
| ConfigParameterDef(name="noise_scale", required=False, default_value=None), | ||
| ConfigParameterDef(name="noise_variance", required=False, default_value=None), | ||
| ConfigParameterDef(name="noise_seed", required=False, default_value=None) | ||
|
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. Bug: Default Seed Value Not HonoredThe
Author
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. I remember getting confused by this one. |
||
| ] | ||
|
|
||
| def make_task( | ||
| self, | ||
|
|
||
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.
Bug: Silence Debugging Noise
Multiple
print()statements for debugging noise injection were left in the code. These will clutter output during production merges and should be removed or replaced with proper logging.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.
To remove before merging