Skip to content

Commit

Permalink
Gemma: Add logit soft-capping to score function. (#1712)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanMullins authored Jul 26, 2024
1 parent 8824388 commit fa0fbb7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions keras_nlp/src/models/gemma/gemma_causal_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ def default_layer_intercept_fn(x, unused_i):
x = self.backbone.layer_norm(x)
logits = self.backbone.token_embedding(x, reverse=True)

if self.backbone.final_logit_soft_cap is not None:
logits = ops.divide(logits, self.backbone.final_logit_soft_cap)
logits = ops.multiply(
ops.tanh(logits), self.backbone.final_logit_soft_cap
)

if scoring_mode == "logits":
return logits

Expand Down

0 comments on commit fa0fbb7

Please sign in to comment.