# Path: t5x/losses.py
# def cross_entropy_with_logits(logits: jnp.ndarray, targets: jnp.ndarray,
#                               z_loss: float) -> jnp.ndarray:
# def _cross_entropy_with_logits_fwd(
#     logits: jnp.ndarray,
#     targets: jnp.ndarray,
#     z_loss: float = 0.0
# ) -> Tuple[jnp.ndarray, Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray, jnp
# def _cross_entropy_with_logits_bwd(
#     res: Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray, jnp.ndarray, jnp.ndarray,
#                jnp.ndarray, jnp.ndarray], g: Tuple[jnp.ndarray, jnp.ndarray]
# ) -> Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray]:
# def compute_weighted_cross_entropy(
#     logits: jnp.ndarray,
#     targets: jnp.ndarray,
#     weights: Optional[jnp.ndarray] = None,
#     label_smoothing: float = 0.0,
#     z_loss: float = 0.0,
#     loss_normalizing_factor: Optional[float] = None
# ) -> Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray]:
# def convert_special_loss_normalizing_factor_to_enum(
#     x: str) -> SpecialLossNormalizingFactor:
# def get_loss_normalizing_factor_and_weights(
#     loss_normalizing_factor: Optional[Union[float, int, str,
#                                             SpecialLossNormalizingFactor]],
#     batch: Mapping[str, jnp.ndarray]):
# class SpecialLossNormalizingFactor(enum.Enum):
#   NUM_REAL_TARGET_TOKENS = 1
#   NUM_TOTAL_TARGET_TOKENS = 2
#   AVERAGE_PER_SEQUENCE = 3


from absl.testing import absltest
from t5x import losses
import jax
import jax.numpy as jnp
import numpy as np
# Copyright 2022 The T5X Authors.
#
# 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
#
#     http://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.

"""Tests for t5x.losses."""



class LossTest(absltest.TestCase):

  def test_xent(self):

    def lossfn(logits, targets, weights):

# Path: t5x/losses.py
# def cross_entropy_with_logits(logits: jnp.ndarray, targets: jnp.ndarray,
#                               z_loss: float) -> jnp.ndarray:
# def _cross_entropy_with_logits_fwd(
#     logits: jnp.ndarray,
#     targets: jnp.ndarray,
#     z_loss: float = 0.0
# ) -> Tuple[jnp.ndarray, Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray, jnp
# def _cross_entropy_with_logits_bwd(
#     res: Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray, jnp.ndarray, jnp.ndarray,
#                jnp.ndarray, jnp.ndarray], g: Tuple[jnp.ndarray, jnp.ndarray]
# ) -> Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray]:
# def compute_weighted_cross_entropy(
#     logits: jnp.ndarray,
#     targets: jnp.ndarray,
#     weights: Optional[jnp.ndarray] = None,
#     label_smoothing: float = 0.0,
#     z_loss: float = 0.0,
#     loss_normalizing_factor: Optional[float] = None
# ) -> Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray]:
# def convert_special_loss_normalizing_factor_to_enum(
#     x: str) -> SpecialLossNormalizingFactor:
# def get_loss_normalizing_factor_and_weights(
#     loss_normalizing_factor: Optional[Union[float, int, str,
#                                             SpecialLossNormalizingFactor]],
#     batch: Mapping[str, jnp.ndarray]):
# class SpecialLossNormalizingFactor(enum.Enum):
#   NUM_REAL_TARGET_TOKENS = 1
#   NUM_TOTAL_TARGET_TOKENS = 2
#   AVERAGE_PER_SEQUENCE = 3


# Path: t5x/losses_test.py
from absl.testing import absltest
from t5x import losses
import jax
import jax.numpy as jnp
import numpy as np

# Copyright 2022 The T5X Authors.
#
# 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
#
#     http://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.

"""Tests for t5x.losses."""



class LossTest(absltest.TestCase):

  def test_xent(self):

    def lossfn(logits, targets, weights):

      loss, z_loss, weight_sum = losses.compute_weighted_cross_entropy(