"git@developer.sourcefind.cn:OpenDAS/apex.git" did not exist on "713e0fb859c0299269eb038cf95e232ae2086444"
Commit 5bf1cc5f authored by A. Unique TensorFlower's avatar A. Unique TensorFlower
Browse files

Ensure sample_top_k samples a valid number in SamplingModule.

PiperOrigin-RevId: 452839394
parent 6ddc94f6
......@@ -55,6 +55,8 @@ def sample_top_k(logits, top_k):
Returns:
Logits with top_k filtering applied.
"""
top_k = tf.clip_by_value(
top_k, clip_value_min=1, clip_value_max=tf.shape(logits)[-1])
top_k_logits = tf.math.top_k(logits, k=top_k)
indices_to_remove = logits < tf.expand_dims(top_k_logits[0][..., -1], -1)
top_k_logits = set_tensor_by_indices_to_value(logits, indices_to_remove,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment