Commit 3b375af
authored
Added OrbaxCheckpoint for keras 3.0 for Data centric saving and restore (#21762)
* Added OrbaxCheckpoint for keras 3.0 for Data centric saving and restore Supports following feature - Asynchronous Checkpointing - Composite Checkpointing - Preservation Policies - Save Decision Policies - Transformations - Custom Handlers
* Fix unused variable in orbax checkpoint test
* fixed failing cases
* fixed review comments
* Improve OrbaxCheckpoint implementation
- Remove conditional export decorator to ensure OrbaxCheckpoint is always available
- Remove unnecessary exception handling in state tree operations
- Update process index check comment for clarity
- Format code to comply with 80-character line limit
- Add distribution_lib modules for backend-specific distributed training support
* Fix code formatting and remove unused variable
- Remove unused 'result' variable in _reconstruct_state_tree_with_values
- Fix long comment line in test file
- Apply code formatting changes
* Add OrbaxCheckpoint callback with conditional exports and improved test handling
- Implement OrbaxCheckpoint callback for async checkpointing with state tree handling
- Add conditional exports for optional orbax-checkpoint dependency
- Use pytest.importorskip for clean optional dependency testing
- Ensure graceful handling when orbax-checkpoint is not installed
* Improve OrbaxCheckpoint: preserve nested structures, enhance tests
- Preserve nested state tree structures instead of flattening for better layer name preservation
- Add backward compatibility for old flattened format checkpoints
- Simplify test class by using self.get_temp_dir() instead of setUp/tearDown
- Remove silent pytest.importorskip, add explicit skip conditions for backend-specific tests
- Move process_id function from backend to distribution module
- Update imports to use centralized LazyModule for orbax.checkpoint
- Test across all backends (JAX, TensorFlow, PyTorch) - all passing
* Fixed review comments
* Migration to Orbax V1
* Fix sklearn wrapper CI tests by marking pipeline consistency checks as expected failures
Neural networks are inherently non-deterministic, so pipeline consistency
checks should be skipped rather than fail. Added check_pipeline_consistency
to EXPECTED_FAILED_CHECKS for all sklearn wrapper types.
* made distributed structure proper
* Fixed sav decision between keras and orbax
* Optimize Orbax checkpoint for JAX backend
- Avoid unnecessary numpy conversion in _get_state_tree() for JAX backend
- Preserve JAX arrays during saving instead of converting to numpy
- Maintain cross-backend compatibility with proper loading conversions
- Update async waiting to use CheckpointManager.wait_until_finished()
- Implement AlwaysSavePolicy for reliable save decisions
- Add expected failures for sklearn tests due to neural network non-determinism
* Optimize Orbax checkpoint for JAX backend with compatibility check
- Preserve JAX arrays during saving when jax.monitoring.record_scalar is available
- Fall back to numpy conversion for older JAX versions that don't have record_scalar
- Maintain cross-backend compatibility while avoiding unnecessary conversions
- Update async waiting to use CheckpointManager.wait_until_finished()
- Implement AlwaysSavePolicy for reliable save decisions
- Add expected failures for sklearn tests due to neural network non-determinism
* added checkpointer.wait()
* Improve OrbaxCheckpoint callback with optimizations and cleanup
- Optimize JAX array handling: avoid unnecessary numpy conversions for JAX >= 0.7.0
- Simplify step counting: use _total_batches_seen directly instead of dual mechanisms
- Remove impossible error checks and verbose messages
- Clean up unused Orbax exports that violated import policies
- Update error message for consistency
- All changes maintain backward compatibility and pass tests across JAX/TensorFlow/PyTorch backends
* Simplify OrbaxCheckpoint API to match ModelCheckpoint parity
- Remove extra features: save_metadata, save_data_iterator, post_finalization_callback, save_decision_policy, keep_period
- Remove loading methods: load_checkpoint, load_latest, all_steps, _restore_model_state_from_full_tree
- Replace save_optimizer_state/save_metrics_state with save_weights_only parameter
- Add comprehensive test coverage for all remaining functionality
- Maintain async saving and preservation policies as Orbax-specific advantages
- All tests pass across JAX/TensorFlow/PyTorch backends
* Removed the experimental import
* Add comprehensive OrbaxCheckpoint tests with loading verification
- Add test_checkpoint_loading: Verifies weights can be loaded from checkpoints
- Add test_checkpoint_loading_weights_only: Tests save_weights_only=True loading
- Add test_checkpoint_loading_with_optimizer_state: Tests full state loading with optimizer
- Fix array comparison logic for JAX, TensorFlow, and PyTorch backends
- Ensure all lines are within 80-character limit
- All tests pass on JAX, TensorFlow, and PyTorch backends
* Improve OrbaxCheckpoint: complete state preservation, cross-backend compatibility, and comprehensive testing
- Add complete model state saving (trainable/non-trainable vars, optimizer, metrics)
- Simplify save_weights_only logic to use full state tree when saving complete state
- Remove unnecessary try-except fallback for wait() method (V1 API always has it)
- Add comprehensive test coverage (13 tests) for all state components
- Ensure cross-backend compatibility (JAX, TensorFlow, PyTorch)
- Remove version dependencies and conditional imports
- Update requirements-common.txt with orbax-checkpoint dependency
* Add back try-except fallback for wait() method to support older Orbax versions
* Use hasattr check instead of try-except for wait() method compatibility
* Add JAX monitoring compatibility: mock jax.monitoring.record_scalar when missing
- Prevents AttributeError in CI environments with older JAX versions
- Adds no-op lambda function when record_scalar is not available
- Ensures tests run across different JAX versions
- All 13 tests pass on JAX, TensorFlow, and PyTorch backends
* Re-run CI
* Refactor LazyModule to use OrbaxLazyModule subclass for cleaner orbax.checkpoint.v1 import handling
* Re-run CI
* Changed the order of the param1 parent 74fba84 commit 3b375af
File tree
7 files changed
+904
-0
lines changed- keras
- api
- _tf_keras/keras/callbacks
- callbacks
- src
- callbacks
- utils
7 files changed
+904
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
0 commit comments