tensorflow / tensorflow/probability

Saving a Keras model that includes a mixture layer (e.g. MixtureNormal) might be unsafe

Open
#1,825 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hi Team,

I am trying to save the weights of a Keras model that end with a MixtureNormal layer. And I get the following warning:

.../keras/src/saving/serialization_lib.py:(line) 159: UserWarning:The object being serialized includes a `lambda`. This is unsafe. In order to reload the object, you will have to pass `safe_mode=False` to the loading function. Please avoid using `lambda` in the future, and use named Python functions instead. This is the `lambda` being serialized:         lambda t: MixtureNormal.new(  # pylint: disable=g-long-lambda
            t, num_components, event_shape, validate_args),

I know that tfp mixture layers have a strong commitment to lambda functions so you can pass tfp distributions. Is this something you plan to work on?

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 keras/src/saving/serialization_lib.py around line 159, then trace how the MixtureNormal layer is serialized and reloaded. Check the interaction with safe_mode=False and determine whether the reported warning can be avoided or needs explicit documentation; done means the save/reload behavior is resolved or clearly supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
keras, tensorflow
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.