Skip to content

Support None for max_shard_size #2261

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 4 commits into
base: master
Choose a base branch
from

Conversation

laxmareddyp
Copy link
Collaborator

No description provided.

@mattdangerw
Copy link
Member

@laxmareddyp thanks! Can we add a unit test?

Current test here

@pytest.mark.large
def test_sharded_weights(self):
if not sharded_weights_available():
self.skipTest("Sharded weights are not available.")
init_kwargs = {
"vocabulary_size": 1024,
"num_layers": 12,
"num_query_heads": 8,
"num_key_value_heads": 4,
"hidden_dim": 32,
"intermediate_dim": 64,
"head_dim": 4,
"sliding_window_size": 5,
"attention_logit_soft_cap": 50,
"final_logit_soft_cap": 30,
"layer_norm_epsilon": 1e-6,
"query_head_dim_normalize": False,
"use_post_ffw_norm": True,
"use_post_attention_norm": True,
"use_sliding_window_attention": True,
}
backbone = GemmaBackbone(**init_kwargs) # ~422KB
# Save the sharded weights.
preset_dir = self.get_temp_dir()
backbone.save_to_preset(preset_dir, max_shard_size=0.0002)
self.assertTrue(
os.path.exists(os.path.join(preset_dir, "model.weights.json"))
)
self.assertTrue(
os.path.exists(os.path.join(preset_dir, "model_00000.weights.h5"))
)
# Load the sharded weights.
revived_backbone = GemmaBackbone.from_preset(preset_dir)
for v1, v2 in zip(
backbone.trainable_variables, revived_backbone.trainable_variables
):
self.assertAllClose(v1, v2)

@mattdangerw mattdangerw self-assigned this May 20, 2025
@mattdangerw mattdangerw added the kokoro:force-run Runs Tests on GPU label Jun 2, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Jun 2, 2025
@mattdangerw
Copy link
Member

Can you rebase this over the latest changes to see if GPU tests are fixed?

@laxmareddyp laxmareddyp added the kokoro:force-run Runs Tests on GPU label Jun 3, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Runs Tests on GPU label Jun 3, 2025
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.

4 participants