Skip to content

Commit af2476f

Browse files
committed
use tqdm.auto for progress bars
Use tqdm.auto to display GUI progress bars when in jupyter notebooks and console progress bars otherwise. Also tweak travisci for python3 on OSX to hopefully run faster
1 parent 314b786 commit af2476f

15 files changed

+5968
-5746
lines changed

.travis.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ matrix:
1010
- language: generic
1111
os: osx
1212
python: 2.7.14
13-
osx_image: xcode9.3
1413
env: PYTHON=2
14+
osx_image: xcode11
1515
- language: generic
1616
os: osx
1717
python: 3.6.5
18-
osx_image: xcode9.3
1918
env: PYTHON=3
19+
osx_image: xcode11
2020

2121
addons:
2222
apt:
2323
packages:
2424
- libblas-dev
2525
- liblapack-dev
2626
- gfortran
27+
homebrew:
28+
packages:
29+
- python3
2730

2831
before_install:
2932
- |
@@ -33,8 +36,6 @@ before_install:
3336
PIP=pip2
3437
PY=python2
3538
if [ "${PYTHON:0:1}" = "3" ]; then
36-
brew upgrade python
37-
brew install python3
3839
PIP=pip3
3940
PY=python3
4041
fi
@@ -63,3 +64,4 @@ cache:
6364
- apt
6465
- directories:
6566
- $HOME/.cache/pip
67+

implicit/_als.cpp

+1,016-977
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

implicit/_nearest_neighbours.cpp

+1,107-1,059
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

implicit/_nearest_neighbours.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from libcpp cimport bool
1111
from libcpp.vector cimport vector
1212
from libcpp.utility cimport pair
1313

14-
import tqdm
14+
from tqdm.auto import tqdm
1515

1616

1717
cdef extern from "nearest_neighbours.h" namespace "implicit" nogil:
@@ -120,7 +120,7 @@ def all_pairs_knn(items, unsigned int K=100, int num_threads=0, show_progress=Tr
120120
cdef long[:] rows = np.zeros(item_count * K, dtype=int)
121121
cdef long[:] cols = np.zeros(item_count * K, dtype=int)
122122

123-
progress = tqdm.tqdm(total=item_count, disable=not show_progress)
123+
progress = tqdm(total=item_count, disable=not show_progress)
124124
with nogil, parallel(num_threads=num_threads):
125125
# allocate memory per thread
126126
neighbours = new SparseMatrixMultiplier[int, double](item_count)

implicit/als.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
import scipy
99
import scipy.sparse
10-
import tqdm
10+
from tqdm.auto import tqdm
1111

1212
import implicit.cuda
1313

@@ -151,17 +151,15 @@ def fit(self, item_users, show_progress=True):
151151
solver = self.solver
152152

153153
log.debug("Running %i ALS iterations", self.iterations)
154-
with tqdm.tqdm(total=self.iterations, disable=not show_progress) as progress:
154+
with tqdm(total=self.iterations, disable=not show_progress) as progress:
155155
# alternate between learning the user_factors from the item_factors and vice-versa
156156
for iteration in range(self.iterations):
157157
s = time.time()
158158
solver(Cui, self.user_factors, self.item_factors, self.regularization,
159159
num_threads=self.num_threads)
160-
progress.update(.5)
161-
162160
solver(Ciu, self.item_factors, self.user_factors, self.regularization,
163161
num_threads=self.num_threads)
164-
progress.update(.5)
162+
progress.update(1)
165163

166164
if self.calculate_training_loss:
167165
loss = _als.calculate_loss(Cui, self.user_factors, self.item_factors,
@@ -192,13 +190,12 @@ def _fit_gpu(self, Ciu_host, Cui_host, show_progress=True):
192190

193191
solver = implicit.cuda.CuLeastSquaresSolver(self.factors)
194192
log.debug("Running %i ALS iterations", self.iterations)
195-
with tqdm.tqdm(total=self.iterations, disable=not show_progress) as progress:
193+
with tqdm(total=self.iterations, disable=not show_progress) as progress:
196194
for iteration in range(self.iterations):
197195
s = time.time()
198196
solver.least_squares(Cui, X, Y, self.regularization, self.cg_steps)
199-
progress.update(.5)
200197
solver.least_squares(Ciu, Y, X, self.regularization, self.cg_steps)
201-
progress.update(.5)
198+
progress.update(1)
202199

203200
if self.fit_callback:
204201
self.fit_callback(iteration, time.time() - s)

implicit/bpr.cpp

+1,301-1,256
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

implicit/bpr.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import logging
44
import multiprocessing
55
import random
66
import time
7-
import tqdm
7+
from tqdm.auto import tqdm
88

99
from cython.parallel import parallel, prange
1010
from libc.math cimport exp
@@ -183,7 +183,7 @@ class BayesianPersonalizedRanking(MatrixFactorizationBase):
183183
# initialize RNG's, one per thread.
184184
cdef RNGVector rng = RNGVector(num_threads, len(user_items.data) - 1)
185185
log.debug("Running %i BPR training epochs", self.iterations)
186-
with tqdm.tqdm(total=self.iterations, disable=not show_progress) as progress:
186+
with tqdm(total=self.iterations, disable=not show_progress) as progress:
187187
for epoch in range(self.iterations):
188188
correct, skipped = bpr_update(rng, userids, user_items.indices, user_items.indptr,
189189
self.user_factors, self.item_factors,
@@ -212,7 +212,7 @@ class BayesianPersonalizedRanking(MatrixFactorizationBase):
212212
Y = implicit.cuda.CuDenseMatrix(self.item_factors)
213213

214214
log.debug("Running %i BPR training epochs", self.iterations)
215-
with tqdm.tqdm(total=self.iterations, disable=not show_progress) as progress:
215+
with tqdm(total=self.iterations, disable=not show_progress) as progress:
216216
for epoch in range(self.iterations):
217217
correct, skipped = implicit.cuda.cu_bpr_update(userids, itemids, indptr,
218218
X, Y, self.learning_rate,

implicit/datasets/_download.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
except ImportError:
55
from urllib import urlretrieve
66

7-
from tqdm import tqdm
7+
from tqdm.auto import tqdm
88

99

1010
LOCAL_CACHE_DIR = os.path.join(os.path.expanduser("~"), "implicit_datasets")

implicit/datasets/million_song_dataset.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import h5py
22
import time
3-
import tqdm
3+
from tqdm.auto import tqdm
44
import os
55
import logging
66
from scipy.sparse import coo_matrix, csr_matrix
@@ -89,7 +89,7 @@ def _join_summary_file(data, summary_filename="msd_summary_file.h5"):
8989

9090
# join on trackid to the summary file to get the artist/album/songname
9191
track_info = np.empty(shape=(len(track_lookup), 4), dtype=np.object)
92-
with tqdm.tqdm(total=len(track_info)) as progress:
92+
with tqdm(total=len(track_info)) as progress:
9393
for song in msd['metadata']['songs']:
9494
trackid = song[17]
9595
if trackid in track_lookup:

0 commit comments

Comments
 (0)