Skip to content

augmentation: Fix AmplitudeScale crashing on default random_state + more - #1021

Merged
bruAristimunha merged 4 commits into
braindecode:masterfrom
tayal-sarthak:amplitude-scale-rng
May 19, 2026
Merged

bruAristimunha merged 4 commits into
braindecode:masterfrom
tayal-sarthak:amplitude-scale-rng

Conversation

@tayal-sarthak

Copy link
Copy Markdown
Contributor

There are two unrelated drive-by fixes batched together.

1. AmplitudeScale class is dead on arrival

calling AmplitudeScale(probability=1.0) on a batch raises RuntimeError: manual_seed expected a long, but got numpy.random.mtrand.RandomState. the documented random_state=None default also blows up the same way (manual_seed expected a long, but got NoneType).

The root cause sits in amplitude_scale in braindecode/augmentation/functional.py. it builds a torch.Generator and feeds whatever the caller passed into manual_seed, which only accepts a python int. Transform.init wraps random_state via check_random_state which produces a numpy RandomState, and that numpy RandomState gets handed straight in via get_augmentation_params. the class path was never exercised before, which is how the regression slipped in.

repro:

>>> import torch
>>> from braindecode.augmentation import AmplitudeScale
>>> AmplitudeScale(probability=1.0)(torch.rand(4, 8, 100), torch.zeros(4))
RuntimeError: manual_seed expected a long, but got numpy.random.mtrand.RandomState

The fix swaps the torch.Generator path with check_random_state + rng.uniform + torch.as_tensor, the same idiom used by every sibling function in this file (gaussian_noise, channels_shuffle, sensors_rotation, band_rotation, ...). int seeds keep reproducibility, numpy RandomState works, None works. docstring tightened to match what the function accepts.

2. broken 404 author link in docs

(viewable inside of the code for jon-dan Thank you!
closes #1017

@bruAristimunha

Copy link
Copy Markdown
Collaborator

many thanks @tayal-sarthak, good PR!

@bruAristimunha
bruAristimunha merged commit 41851bb into braindecode:master May 19, 2026
8 of 11 checks passed
@bruAristimunha bruAristimunha mentioned this pull request May 19, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken links detected in documentation

2 participants