Skip to content

Commit

Permalink
Merge pull request #2071 from recommenders-team/miguel/fix_tf
Browse files Browse the repository at this point in the history
Fixing TF to < 2.16
  • Loading branch information
miguelgfierro authored Mar 19, 2024
2 parents d8e8ac3 + 21492c9 commit 14c5c93
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions recommenders/models/fastai/fastai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,22 @@ def score(

# score the pytorch model
x = torch.column_stack((u, m))

if torch.cuda.is_available():
x = x.to("cuda")
learner.model = learner.model.to("cuda")

pred = learner.model.forward(x).detach().cpu().numpy()
scores = pd.DataFrame(
{user_col: test_df[user_col], item_col: test_df[item_col], prediction_col: pred}
)
scores = scores.sort_values([user_col, prediction_col], ascending=[True, False])

if top_k is not None:
top_scores = scores.groupby(user_col).head(top_k).reset_index(drop=True)
else:
top_scores = scores

return top_scores


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"gpu": [
"fastai>=2.7.11,<3",
"nvidia-ml-py>=11.525.84",
"tensorflow>=2.8.4,!=2.9.0.*,!=2.9.1,!=2.9.2,!=2.10.0.*,<=2.15.0",
"tensorflow>=2.8.4,!=2.9.0.*,!=2.9.1,!=2.9.2,!=2.10.0.*,<2.16", # Fixed TF due to constant security problems and breaking changes #2073
"tf-slim>=1.1.0", # No python_requires in its setup.py
"torch>=2.0.1,<3",
],
Expand Down
8 changes: 5 additions & 3 deletions tests/functional/examples/test_notebooks_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def test_wide_deep_functional(
os.path.join("tests", "resources", "deeprec", "slirec"),
10,
400,
{"auc": 0.7183}, # Don't do logloss check as SLi-Rec uses ranking loss, not a point-wise loss
{
"auc": 0.7183
}, # Don't do logloss check as SLi-Rec uses ranking loss, not a point-wise loss
42,
)
],
Expand Down Expand Up @@ -278,7 +280,7 @@ def test_slirec_quickstart_functional(
results = read_notebook(output_notebook)

assert results["auc"] == pytest.approx(expected_values["auc"], rel=TOL, abs=ABS_TOL)


@pytest.mark.gpu
@pytest.mark.notebooks
Expand Down Expand Up @@ -567,7 +569,7 @@ def test_dkn_quickstart_functional(notebooks, output_notebook, kernel_name):
notebook_path,
output_notebook,
kernel_name=kernel_name,
parameters=dict(EPOCHS=5, BATCH_SIZE=500),
parameters=dict(EPOCHS=5, BATCH_SIZE=200),
)
results = read_notebook(output_notebook)

Expand Down

0 comments on commit 14c5c93

Please sign in to comment.