Skip to content

Add StableLM-3B 4E1T to Keras Hub #2151

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
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

Bond099
Copy link

@Bond099 Bond099 commented Mar 18, 2025

This PR adds the StableLM-3B 4E1T model to Keras Hub. However, numerical matching with the Hugging Face implementation is still in progress.

@Bond099
Copy link
Author

Bond099 commented Mar 22, 2025

@divyashreepathihalli Here is a comparison of numerics with Hugging Face in Colab. The results match with an absolute tolerance of 1e-3, but they do not match when using 1e-5. Could you please take a look and suggest some improvements or explanations for this discrepancy?

@divyashreepathihalli divyashreepathihalli added the kokoro:force-run Runs Tests on GPU label Mar 24, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Mar 24, 2025
@sachinprasadhs sachinprasadhs added the WIP Pull requests which are work in progress and not ready yet for review. label Apr 11, 2025
@divyashreepathihalli
Copy link
Collaborator

The numerics is good enough!

@Bond099 Bond099 marked this pull request as ready for review May 15, 2025 09:58
Copy link
Collaborator

@abheesht17 abheesht17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, but let's check the numerics and the generate output.

self._inv_norm_factor = 1.0 / math.sqrt(head_dim)

# Query projection (no bias )
self._query_dense = keras.layers.EinsumDense(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just name layers without the underscore at the beginning. So, self.query_dense.

self.rotary_dim = int(head_dim * self.rotary_percentage)
self._inv_norm_factor = 1.0 / math.sqrt(head_dim)

# Query projection (no bias )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Remove the space after bias?

Comment on lines +33 to +34
num_layers: int. The number of transformer layers (32 for
StableLM-3B4E1T).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't need (32 for StableLM-2B4E1T) here (and elsewhere too), since it'll be part of the config anyway. Let's remove.

@mattdangerw
Copy link
Member

@Bond099 let's sync this with the latest changes and make sure to run our format script. I'm not exactly sure why non of our CI is running, but I don't think it ran.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Pull requests which are work in progress and not ready yet for review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants