# NotImplementedError: Saving the model to HDF5 format is not supported when the model has multiple outputs with different loss functions

- **ID:** `tensorflow/keras-model-save-h5-weights`
- **Domain:** tensorflow
- **Category:** config_error
- **Error Code:** `KHS`
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

Keras HDF5 serialization does not support models with heterogeneous loss functions across multiple outputs; the format cannot correctly store the loss configuration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| tensorflow>=2.11.0 | active | — | — |
| keras>=2.11 | active | — | — |
| python>=3.8 | active | — | — |

## Workarounds

1. **Save the model using the SavedModel format instead: `model.save('my_model', save_format='tf')` (or `model.export('my_model')` in TF2.x). This format supports multiple outputs and heterogeneous losses.** (95% success)
   ```
   Save the model using the SavedModel format instead: `model.save('my_model', save_format='tf')` (or `model.export('my_model')` in TF2.x). This format supports multiple outputs and heterogeneous losses.
   ```
2. **Save only the model weights using `model.save_weights('model_weights.h5')` and then recreate the model architecture with the same loss configuration in code, then load the weights.** (85% success)
   ```
   Save only the model weights using `model.save_weights('model_weights.h5')` and then recreate the model architecture with the same loss configuration in code, then load the weights.
   ```

## Dead Ends

- **Manually editing the HDF5 file to add loss entries.** — HDF5 files are binary and not meant for manual editing; the internal structure is complex and likely to break the model loading. (95% fail)
- **Setting all loss functions to the same value temporarily to save, then restoring them.** — Even if the save succeeds, the model's loss configuration is lost; loading the model will have incorrect loss functions. (70% fail)
