tensorflow / tensorflow/java

Export Gemma 2 from Keras to Saved Model?

Open
#595 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
928
Forks
227
PR merge metrics
No merged PRs in 30d

Description

Ok, downloaded Gemma2 from
https://www.kaggle.com/models/google/gemma-2/keras

-unpacked and got the following files:

/assets
config.json
metadata.json
model.weights.h5
tokenizer.json

-tried to load model by using following Python script:

import json
from tensorflow import keras

# 1. Path to the config and weights:
config_path = "d:/Install/TensorFlow/models/Gemma_2/config.json"
weights_path = "d:/Install/TensorFlow/models/Gemma_2/model.weights.h5"
saved_model_dir = "d:/Install/TensorFlow/models/Gemma_2/gemma2_saved_model"

# 2. load model configuration
with open(config_path, 'r') as f:
    model_config = json.load(f)

# 3. Reconstruct the model:
model = keras.models.model_from_json(json.dumps(model_config))

# 4. Load the weights:
model.load_weights(weights_path)

# 5. Finally, save model as  TensorFlow SavedModel format:
model.save(saved_model_dir, save_format="tf")

print("Model saved to the :", saved_model_dir)

-at the line

model = keras.models.model_from_json(json.dumps(model_config))

got following error:

ValueError: Unknown layer: GemmaBackbone. Please ensure this object is passed to the custom_objectsargument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

Questions:

but not sure what to do with GemmaBackbone...huh?

any help?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Python script, especially the model_from_json call that fails on GemmaBackbone, and review the downloaded config.json, model.weights.h5, and tokenizer.json. Determine whether this repository supports exporting this Gemma 2 package to SavedModel; done means documenting a supported workflow or clearly explaining that it is not supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.