google / generative-ai-docs

Documentation for Google's Gen AI site - including the Gemini API and Gemma
https://ai.google.dev
Apache License 2.0
1.46k stars 498 forks source link

How to save fine tuned PaliGemma model? #424

Closed SkalskiP closed 1 month ago

SkalskiP commented 1 month ago

Description of the feature request:

Hi 👋🏻

Thanks a lot for PaliGemma fine-tune example notebook. It worked without any issue. However, it lacks the last step - saving a fine-tuned model. (Or I'm just missing something.) I'd appreciate any help. Thank you. 🙏🏻

What problem are you trying to solve with this feature?

No response

Any other information you'd like to share?

No response

gokayfem commented 1 month ago

+1 We need this

selamw1 commented 1 month ago

Hi @SkalskiP,

Based on this conversation at X, you can use numpy.savez, a function that efficiently stores multiple arrays in a single, uncompressed .npz format.

import big_vision.utils as bv_utils
flat, _ = bv_utils.tree_flatten_with_names(flat)
with open("ckpt.npz", "wb") as f:
  np.savez(f, **{k: v for k, v in flat})

And then load:

bv_utils.load_checkpoint_np("ckpt.npz")
SkalskiP commented 1 month ago

Thanks a lot! @gokayfem I really appreciate the help.

milaomrani commented 3 weeks ago

what is flat? what should I replace here? flat, _ = bv_utils.tree_flatten_with_names(flat)

gokayfem commented 3 weeks ago

It should be

flat, _ = bv_utils.tree_flatten_with_names(params)