Source code for easydel.trainers.trainer.modeling_output

# Copyright 2025 The EasyDeL Author @erfanzar (Erfan Zare Chavoshi).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Training output data structures.

This module defines the output types returned by training operations,
including the final state and associated metadata from training runs.
"""

from __future__ import annotations

import typing as tp

import jax
from eformer.pytree import auto_pytree

if tp.TYPE_CHECKING:
    from easydel.infra.base_state import EasyDeLState
else:
    EasyDeLState = tp.Any
CallFN: tp.TypeAlias = tp.Any | tp.Mapping[str, tp.Callable] | dict[str, tp.Callable]


[docs]@auto_pytree class TrainerOutput: """Output from a training run. Contains the final model state and metadata from the training process, including checkpointing information and utility functions for state manipulation. Attributes: state: The final EasyDeLState after training completion. mesh: The JAX sharding mesh used during training, if any. checkpoint_manager: Manager object for handling model checkpoints. gather_fns: Functions for gathering sharded parameters to host. shard_fns: Functions for sharding parameters across devices. last_save_file_name: Name of the most recently saved checkpoint file. checkpoint_path: Full path to the checkpoint directory. """ state: EasyDeLState mesh: jax.sharding.Mesh | None checkpoint_manager: tp.Any gather_fns: CallFN | None = None shard_fns: CallFN | None = None last_save_file_name: str | None = None checkpoint_path: str | None = None