Repository navigation
Add REVE model - #866
Add REVE model#866jonathanlys01 wants to merge 0 commit into
Conversation
bruAristimunha
left a comment
There was a problem hiding this comment.
This is good, but a few small things are needed:
- Longer descriptions, more details, and details for each figure.
- More descriptive variable names; nothing like b, c, p; they should be more descriptive so the user can understand them.
- The positional bank needs to be more accessible.
- The integration tests will already check if the model can be run.
|
Can you fill the what's new file please and export the model parameters within the utils? |
There was a problem hiding this comment.
Pull request overview
This PR adds the REVE (Representation for EEG with versatile embeddings) model to braindecode, implementing a foundation model for EEG that uses 4D positional embeddings and transformer architecture to process EEG signals. The implementation is based on the paper by El Ouahidi et al. (2025).
- Implements the REVE model with patch-based EEG tokenization and 4D positional encoding
- Includes a position bank that downloads channel positions from HuggingFace at initialization
- Supports both standard flattened output and attention pooling for classification tasks
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 21 comments.
| File | Description |
|---|---|
| braindecode/models/reve.py | Complete implementation of the REVE model including the main model class, transformer components, 4D positional embeddings, and position bank integration |
| braindecode/models/init.py | Exports the REVE model to make it available in the braindecode.models namespace |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| to_patch_embedding = nn.Sequential(nn.Linear(patch_size, embed_dim)) | ||
| return to_patch_embedding |
There was a problem hiding this comment.
[nitpick] The function patch_embedding returns a nn.Sequential with only one layer, which is unnecessarily wrapped. The function could simply return nn.Linear(patch_size, embed_dim) directly, or the nn.Sequential wrapper should be removed since it adds no value with a single layer.
If the intent is to allow for future expansion with additional layers, that should be documented. Otherwise, this is an unnecessary layer of indirection.
| to_patch_embedding = nn.Sequential(nn.Linear(patch_size, embed_dim)) | |
| return to_patch_embedding | |
| return nn.Linear(patch_size, embed_dim) |
There was a problem hiding this comment.
I tested this, it silently breaks the parameter loading of the patch embedding parameters.
I again highly support the introduction of tests that will check for the equality of the output with the hugging face model and the braindecode version.
Something like:
from braindecode.models import REVE
import torch
from transformers import AutoModel
batch_size = 2
n_chans = 32
n_times = 1000
n_outputs = 10
cache_dir = "./cache"
ch_list = [f"E{i + 1}" for i in range(n_chans)]
eeg_input = torch.randn(batch_size, n_chans, n_times)
model_braindecode: REVE = REVE.from_pretrained(
"brain-bzh/reve-base",
cache_dir=cache_dir,
n_times=n_times,
n_chans=n_chans,
n_outputs=n_outputs,
)
pos_braindecode = model_braindecode.get_positions(ch_list)
pos_braindecode = pos_braindecode.unsqueeze(0).repeat(batch_size, 1, 1)
model_hf = AutoModel.from_pretrained(
"brain-bzh/reve-base",
cache_dir=cache_dir,
trust_remote_code=True,
)
pos_bank_hf = AutoModel.from_pretrained(
"brain-bzh/reve-positions",
cache_dir=cache_dir,
trust_remote_code=True,
)
pos_hf = pos_bank_hf(ch_list)
pos_hf = pos_hf.unsqueeze(0).repeat(batch_size, 1, 1)
# return_output is True to bypass the final layer
output_braindecode = model_braindecode(eeg_input, pos_braindecode, return_output=True)
output_hf = model_hf(eeg_input, pos_hf, return_output=True)
print("positions allclose:", torch.allclose(pos_braindecode, pos_hf, atol=1e-6))
print("outputs allclose:", torch.allclose(output_braindecode[-1], output_hf[-1], atol=1e-6))|
Almost all the comments for the copilot are validated and need to be addressed, except for the test that we already covered with the integration test, which follows the Timm style. There are some more style details about layer names and how to become fully compatible with braindecode and still be able to load the weights, but I can address them when everything is resolved from the copilot initial review and the tests are green. |
|
I agree with all copilot comments about the style, there's just the small issue about the patch embedding layer being a Sequential with a single element, but replacing it with a plain linear silently breaks the loading of the parameters through hugging face (see this comment). |
|
I am supporting of the new test, please let me know if you need any help. It should be quite straightforward to do with Copilot, including transformer as a dependency for the test, and a test following PyTest style. Please let me know if you need any help. |
|
Added the test, you will probably have to add a hugging face token in the GitHub secrets because the repository for REVE is gated. |
|
Hey @jonathanlys01, I tried, and it didn't work. Can you find a way to block only the weights? Or maybe host in another repository. And btw, we are planning to launch next Friday, or when MNE-bids release. If we don't integrate it by next Friday, it will be included in the next release, possibly at the end of February. I'm working on the promotional materials this next week, canvas, video, and LinkedIn post. |
|
The goal is specifically to ensure the weights integrity, I think it works if you manage to add an HF token as a secret then load it as an env variable and pass it to the from_pretrained method through the |
|
Sorry, I couldn't do it. I haven't found a way to do this without linking my personal Hugging Face permission, which would require an additional key that we would have to maintain. Perhaps there's a way to grant permission within the BrainDecode organization. I still think it's a terrible idea to implement this gatekeeping. It is fundamentally against the principle of accessibility to more FAIR science. This is everything we are historically against in Moabb. However, we are at braindecode, so I don't want to block the merge, so I'm granting you the temporary maintenance permission to add you to the secret. |
|
here is the braindecode org at hugging face: https://huggingface.co/braindecode |
|
Hello @bruAristimunha , I've worked on the integration a bit:
Let me know if there is anything left to do before merging. |
|
Can you just double check the comments from copilot first revision? If you think it is okay, just resolved. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #866 +/- ##
========================================
Coverage 87.77% 87.78%
========================================
Files 111 112 +1
Lines 10011 10247 +236
========================================
+ Hits 8787 8995 +208
- Misses 1224 1252 +28 🚀 New features to boost your workflow:
|
|
I think we are ready to merge @bruAristimunha ! |
|
Super nice to have your model in Braindecode, thanks @jonathanlys01 !! |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
deepinv:1
- This appears to be an unrelated subproject commit addition. Consider removing this from the REVE model PR or explaining its relevance in the PR description.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@codex review please |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
deepinv:1
- This appears to be an unrelated Git submodule addition that is not mentioned in the PR description. If this is intentional, it should be documented in the PR description or removed if added accidentally.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
It's okay for me @jonathanlys01! However, I made several modifications to the documentation. Can you check the render documentation @jonathanlys01, @glioi, and @elouayas? To download the documentation locally, you will need to click on this link: I'm waiting for your OK to apply the merge. |
e43f10f to
3a842a0
Compare
|
I made one small change when I was trying to create the redirect link for the doc. Now the PR got moved for this: #876, but @jonathanlys01 still has the writing access. Sorry for my git issue. |
This is a first attempt at integrating the REVE model to braindecode.
More documentation will follow once the implementation and usage are validated by the team.
To verify model instantiation and Hugging Face loading, you can run the following (a separate PR will add proper tests if this proves sufficient):