Skip to content
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

Feat/L2 Regularization #270

Merged
merged 9 commits into from
Jan 18, 2025
Merged

Feat/L2 Regularization #270

merged 9 commits into from
Jan 18, 2025

Conversation

L-M-Sherlock
Copy link
Member

@L-M-Sherlock L-M-Sherlock added the enhancement New feature or request label Jan 10, 2025
@Expertium
Copy link
Contributor

Expertium commented Jan 14, 2025

I'm currently trying out a different regularization method (well, it wasn't really made for regularization, but it kind of acts like a regularizer and improves generalization). If it works well, we can ditch L2 which barely improves the metrics. So don't merge this just yet. And you'd have to un-merge related PRs, but oh well.

@Expertium
Copy link
Contributor

The results ended up being underwhelming.
I implemented AutoClip for gradients. Relevant repo: https://github.com/pseeth/autoclip. The code is very simple, I implemented it in other.py in just 16 lines.
The key idea is simple: keep track of observed gradient norms, calculate the p-th percentile (clip_value = np.percentile(grad_history, clip_percentile)) of them, then if next time the gradient norm exceeds that value, use torch.nn.utils.clip_grad_norm_(self.model.parameters(), clip_value). This is kind of like outlier filtering, but with gradients.
From their paper:
image

The authors recommend using p=10 aka 10th percentile, which is extremely aggressive, but perhaps suitable for large neural nets.
image
I tried different values of clip_percentile on FSRS-5, and sadly it barely improves the metrics.
So let's use L2 regularization.

@L-M-Sherlock
Copy link
Member Author

L-M-Sherlock commented Jan 17, 2025

Wow, L2 regularization has a very significant impact on the distribution of w[12], w[14], w[15], w[16]

image image image image

@L-M-Sherlock L-M-Sherlock merged commit f11c30d into main Jan 18, 2025
3 checks passed
@L-M-Sherlock L-M-Sherlock deleted the Feat/L2-Regularization branch January 18, 2025 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants