Skip to content

Commit

Permalink
fix randomness of stochastic_swap_noise tests (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
sararb authored May 19, 2023
1 parent 2c9ab40 commit e5fa050
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/unit/torch/tabular/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
# limitations under the License.
#

import numpy as np
import pytest
import torch
from merlin.schema import Tags

import transformers4rec.torch as tr
from merlin_standard_lib import schema

np.random.seed(0)
torch.manual_seed(0)


@pytest.mark.parametrize("replacement_prob", [0.1, 0.3, 0.5, 0.7])
def test_stochastic_swap_noise(replacement_prob):
Expand Down
7 changes: 7 additions & 0 deletions transformers4rec/torch/utils/schema_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import random
from typing import Any, Dict, Optional

import numpy as np
import torch
from merlin.schema.io.proto_utils import has_field

Expand All @@ -32,9 +33,15 @@ def random_data_from_schema(
min_session_length: int = 5,
device=None,
ragged=False,
seed=0,
) -> TabularData:
data: Dict[str, Any] = {}

random.seed(seed)
np.random.seed(seed)
if seed:
torch.manual_seed(seed)

for i in range(num_rows):
session_length = None
if max_session_length:
Expand Down

0 comments on commit e5fa050

Please sign in to comment.