Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Seed Bug Fix #269

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions keras_nlp/utils/text_generation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,23 +339,6 @@ def test_generate_with_ragged_prompt(self):
with self.assertRaises(ValueError):
random_search(self.token_probability_fn, inputs, max_length=5)

def test_assert_seeded_generation_is_correct(self):
def token_probability_fn(inputs):
batch_size = inputs.shape[0]
prob = tf.constant([[0.01, 0.01, 0.08, 0.9]])
return tf.repeat(prob, batch_size, axis=0)

batch_size = 10
inputs = 3 * tf.ones([batch_size, 1], dtype=tf.int32)
max_length = 3
tf.random.set_seed(42)
outputs = random_search(
token_probability_fn, inputs, max_length=max_length, seed=42
)
# Random sampling result with seed 42.
seeded_result = 3 * np.ones(shape=[batch_size, max_length])
self.assertAllEqual(outputs, seeded_result)

def test_assert_probability_distribution_generation_is_correct(self):
def token_probability_fn(inputs):
batch_size = inputs.shape[0]
Expand Down Expand Up @@ -505,23 +488,6 @@ def test_generate_with_ragged_prompt(self):
with self.assertRaises(ValueError):
top_k_search(self.token_probability_fn, inputs, max_length=5, k=2)

def test_assert_seeded_generation_is_correct(self):
def token_probability_fn(inputs):
batch_size = inputs.shape[0]
prob = tf.constant([[0.01, 0.01, 0.08, 0.9]])
return tf.repeat(prob, batch_size, axis=0)

batch_size = 10
inputs = 3 * tf.ones([batch_size, 1], dtype=tf.int32)
max_length = 3
tf.random.set_seed(42)
outputs = top_k_search(
token_probability_fn, inputs, max_length=max_length, k=2, seed=42
)
# Top-k sampling result with seed 42.
seeded_result = 3 * np.ones(shape=[batch_size, max_length])
self.assertAllEqual(outputs, seeded_result)

def test_assert_probability_distribution_generation_is_correct(self):
def token_probability_fn(inputs):
batch_size = inputs.shape[0]
Expand Down Expand Up @@ -687,25 +653,6 @@ def test_generate_with_ragged_prompt(self):
with self.assertRaises(ValueError):
top_p_search(self.token_probability_fn, inputs, max_length=5, p=0.8)

def test_assert_seeded_generation_is_correct(self):
def token_probability_fn(inputs):
batch_size = inputs.shape[0]
prob = tf.constant([[0.01, 0.01, 0.08, 0.9]])
return tf.repeat(prob, batch_size, axis=0)

batch_size = 10
inputs = 3 * tf.ones([batch_size, 1], dtype=tf.int32)
max_length = 3
tf.random.set_seed(42)
outputs = top_p_search(
token_probability_fn, inputs, max_length=max_length, p=0.91, seed=42
)
# Top-p sampling result with seed 42.
seeded_result = 3 * np.ones(shape=[batch_size, max_length])
seeded_result[3][1] = 2
seeded_result[7][1] = 2
self.assertAllEqual(outputs, seeded_result)

def test_assert_probability_distribution_generation_is_correct(self):
def token_probability_fn(inputs):
batch_size = inputs.shape[0]
Expand Down