Task-specific loss function. See BaseTask.
(
model_config: ml_collections.FrozenConfigDict,
model_params: Dict[str, Any],
model_vars: Dict[str, Any], # pylint: disable=unused-argument
batch: Dict[str, Any],
deterministic: bool,
dropout_rng: Optional[Dict[str, Array]] = None, # pylint: disable=unused-argument
)
| 59 | """Creates task loss function.""" |
| 60 | |
| 61 | def loss_fn( |
| 62 | model_config: ml_collections.FrozenConfigDict, |
| 63 | model_params: Dict[str, Any], |
| 64 | model_vars: Dict[str, Any], # pylint: disable=unused-argument |
| 65 | batch: Dict[str, Any], |
| 66 | deterministic: bool, |
| 67 | dropout_rng: Optional[Dict[str, Array]] = None, # pylint: disable=unused-argument |
| 68 | ) -> Tuple[float, MetricGroups, Dict[str, Any]]: |
| 69 | """Task-specific loss function. See BaseTask.""" |
| 70 | encoding = cls.build_model(model_config).apply( |
| 71 | {'params': model_params}, |
| 72 | batch, |
| 73 | deterministic=deterministic, |
| 74 | ) |
| 75 | |
| 76 | loss = jnp.sum(encoding) |
| 77 | metrics = { |
| 78 | 'agg': { |
| 79 | 'loss': loss, |
| 80 | 'denominator': batch['x'].shape[0], |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return loss, metrics, {} # pytype: disable=bad-return-type # jnp-type |
| 85 | |
| 86 | return loss_fn |
| 87 |
nothing calls this directly
no test coverage detected