Skip to content

Commit 1027ca2

Browse files
authored
Install implicit from conda (#1115)
- Installing from pip installs from source. Faster to install binary from conda - Fixes build issues since we are building the GPU image with stubs. - Added a smoke test http://b/211665716
1 parent b47cb41 commit 1027ca2

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

Dockerfile.tmpl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ RUN conda install cudf=21.10 cuml=21.10 cudatoolkit=$CUDA_MAJOR_VERSION.$CUDA_MI
7777
/tmp/clean-layer.sh
7878
{{ end }}
7979

80+
# Install implicit
81+
{{ if eq .Accelerator "gpu" }}
82+
RUN conda install implicit implicit-proc=*=gpu && \
83+
/tmp/clean-layer.sh
84+
{{ else }}
85+
RUN conda install implicit && \
86+
/tmp/clean-layer.sh
87+
{{ end}}
88+
8089
# Install PyTorch
8190
{{ if eq .Accelerator "gpu" }}
8291
COPY --from=torch_whl /tmp/whl/*.whl /tmp/torch/
@@ -297,7 +306,6 @@ RUN pip install mpld3 && \
297306
pip install pymongo && \
298307
pip install geoplot && \
299308
pip install eli5 && \
300-
pip install implicit && \
301309
pip install kaggle && \
302310
/tmp/clean-layer.sh
303311

tests/test_implicit.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import unittest
2+
3+
import numpy as np
4+
5+
from implicit.als import AlternatingLeastSquares
6+
from scipy.sparse import csr_matrix
7+
8+
9+
class TestImplicit(unittest.TestCase):
10+
def test_model(self):
11+
raw = [
12+
[0.0, 2.0, 1.5, 1.33333333, 1.25, 1.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
13+
[0.0, 0.0, 2.0, 1.5, 1.33333333, 1.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
14+
[0.0, 0.0, 0.0, 2.0, 1.5, 1.33333333, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
15+
[0.0, 0.0, 0.0, 0.0, 2.0, 1.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
16+
[0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
17+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
18+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.5, 1.33333333, 1.25, 1.2],
19+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.5, 1.33333333, 1.25],
20+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.5, 1.33333333],
21+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.5],
22+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0],
23+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
24+
]
25+
counts = csr_matrix(raw, dtype=np.float64)
26+
27+
model = AlternatingLeastSquares(factors=3)
28+
model.fit(counts, show_progress=False)
29+
rows, cols = model.item_factors, model.user_factors
30+
31+
assert not np.isnan(np.sum(cols))
32+
assert not np.isnan(np.sum(rows))

0 commit comments

Comments
 (0)