Closed lfaucon closed 2 years ago
Thanks for the bug report! It looks like the existing test suite misses this - we have tests to_cpu/to_gpu conversion, as well as the save/load code, but there aren't any tests that test out the recalculate_user/item code after model.save
or to_cpu
. It seems like this bug has existed since I originally added the recalculate_user/item support to the GPU ALS model https://github.com/benfred/implicit/pull/515 =(
I have a fix in https://github.com/benfred/implicit/pull/598
Steps to replicate
implicit.gpu.als.AlternateLeastSquares
to_cpu
thento_gpu
on itrecalculate_user
now causes the errorTypeError: __cinit__() takes exactly 1 positional argument (2 given)
Full example:
Note: The double conversion is not a common usecase. I mention it here only as the simplest way to replicate the error. The error occurs also when saving and loading the model.
Proposed fix
The class
implicit.gpu.Matrix
defined here https://github.com/benfred/implicit/blob/main/implicit/gpu/_cuda.pyx#L87 is used here incorrectly https://github.com/benfred/implicit/blob/main/implicit/gpu/als.py#L271XtX
andYtY
should be initialized asself._XtX = implicit.gpu.Matrix.zeros(self.factors, self.factors)