Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Conversation

vene
Copy link
Collaborator

@vene vene commented Jul 18, 2016

Switch everything to typed memoryviews and inline direct solver update.

20 newsgroups
=============
X_train.shape = (11314, 130107)
X_train.format = csc
X_train.dtype = float64
X_train density = 0.001214353154362896
y_train (11314,)
X_test (7532, 130107)
X_test.format = csc
X_test.dtype = float64
y_test (7532,)

Classifier Training
===================
/home/vlad/code/polylearn/polylearn/factorization_machine.py:118: UserWarning: Objective did not converge. Increase max_iter.
  warnings.warn("Objective did not converge. Increase max_iter.")
Training fm-2 ... done
Training fm-3 ... done
/home/vlad/code/polylearn/polylearn/polynomial_network.py:99: UserWarning: Objective did not converge. Increase max_iter.
  warnings.warn("Objective did not converge. Increase max_iter.")
Training polynet-2 ... done
Training polynet-3 ... done
Classification performance:
===========================

Classifier            train       test         f1   accuracy
------------------------------------------------------------
fm-3               36.3608s    0.3642s     0.4009     0.9663
fm-2               31.7401s    0.1225s     0.6126     0.9740
polynet-3           6.6819s    0.0685s     0.6992     0.9796
polynet-2           5.9581s    0.0693s     0.7310     0.9807

>>> on branch speedup

Classifier            train       test         f1   accuracy
------------------------------------------------------------
fm-3               11.7805s    0.3608s     0.4009     0.9663
fm-2                7.1945s    0.1218s     0.6126     0.9740
polynet-3           6.5308s    0.0676s     0.6992     0.9796
polynet-2           5.9655s    0.0675s     0.7310     0.9807

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.886% when pulling 025c323e6d0788e712276d952846e97bf3cffb87 on speedup into 191fb42 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.886% when pulling 89bdd3e803cc9a17611a16df3028895439a3a159 on speedup into 191fb42 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.886% when pulling 41fdc4ed485ee125b7fee52175d69008919496fb on speedup into 191fb42 on master.

@vene
Copy link
Collaborator Author

vene commented Jul 19, 2016

@fabianp could you give me a hand to figure out why I'm getting these win32/py2 failures? It looks like the cd_direct_fast.pyx solver has numerical issues in this configuration, but I can't pinpoint the cause.

@fabianp
Copy link
Member

fabianp commented Jul 20, 2016

Hey. Went through the file cd_direct_fast.pyx but I don't know what can be causing such failures. Any chance you could make a minimal example for such failures?

@mblondel
Copy link
Member

Since the win32 failures are independent of this PR, I think this PR should be merged, since it is a big improvement. I would also add a benchmark/ folder to help track the improvements over time.

Regarding the failures, could it be that the random kit behave differently on win32?

@fabianp
Copy link
Member

fabianp commented Jul 25, 2016

If that is the case, adding l2 regularization and/or more iterations should
solve the problem

On Jul 25, 2016 2:49 PM, "Mathieu Blondel" notifications@github.com wrote:

Since the win32 failures are independent of this PR, I think this PR
should be merged, since it is a big improvement. I would also add a
benchmark/ folder to help track the improvements over time.

Regarding the failures, could it be that the random kit behave differently
on win32?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAQ8hwPuHbnZQYCovhlsgRQJNBkR_VrZks5qZLDDgaJpZM4JO8xX
.

@mblondel
Copy link
Member

Remember that FMs and PNs are non-convex :)

@mblondel
Copy link
Member

@ogrisel From past experience with scikit-learn, any idea what the win32 failures could come from?

By the way, the problem is only on Python 2.7. Python 3.5 is fine.

@fabianp
Copy link
Member

fabianp commented Jul 25, 2016

D'oh!

On Jul 25, 2016 2:55 PM, "Mathieu Blondel" notifications@github.com wrote:

Remember that FMs and PNs are non-convex :)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAQ8h5Z2gdf70Izpa9Lk0nEZLJJODZdHks5qZLJJgaJpZM4JO8xX
.

Py_ssize_t order,
double* out,
int s,
int degree):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird to use Py_ssize_t for a mathematical variable. Py_ssize_t should only be used to index arrays.

@ogrisel
Copy link

ogrisel commented Jul 25, 2016

Py_ssize_t has a different meaning signed 32 bit int on a 32 bit platform and signed 64 bit int on a 64 bit platform. It should only be used to index datastructures (e.g. arrays or Python lists). I do not understand why the problem does not exist with Python 3 though.

@vene
Copy link
Collaborator Author

vene commented Jul 25, 2016

That makes sense. Thanks, @ogrisel! However the problem still existed when I was using int everywhere. I only replaced it with py_ssize_t in an attempt to fix it, and it seems I got a bit overzealous and replaced too many vars.

I'll change it to use py_ssize_t just where it should.

On July 25, 2016 10:23:48 AM EDT, Olivier Grisel notifications@github.com wrote:

Py_ssize_t has a different meaning signed 32 bit int on a 32 bit
platform and signed 64 bit int on a 64 bit platform. It should only be
used to index datastructures (e.g. arrays or Python lists). I do not
understand why the problem does not exist with Python 3 though.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#1 (comment)

Sent from my Android device with K-9 Mail. Please excuse my brevity.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 97.888% when pulling 64c8876 on speedup into e0d79c2 on master.

@vene
Copy link
Collaborator Author

vene commented Jul 25, 2016

@mblondel I think it's not a rng issue. The y generated in tests/test_factorization_machine.py:check_fit for both degree=2, 3 is the same in AppVeyor as on my 64bit ubuntu machine. I haven't directly checked the initial P_ but I doubt it would be different.

I also fixed the types as suggested by @ogrisel with no difference.

So it's probably something numerical. It's strange that no errors occur with the lifted solver though.

Maybe I should try a 32bit py2 env in linux and see if I can reproduce it.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 97.888% when pulling 64c8876 on speedup into e0d79c2 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 97.888% when pulling 64c8876 on speedup into e0d79c2 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.005%) to 97.88% when pulling e78961e on speedup into e0d79c2 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.005%) to 97.88% when pulling 49a3d7e on speedup into e0d79c2 on master.

@coveralls
Copy link

coveralls commented Jul 26, 2016

Coverage Status

Coverage decreased (-0.005%) to 97.88% when pulling 024e08d on speedup into e0d79c2 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 98.13% when pulling e8d175b on speedup into e0d79c2 on master.

if degree == 2:
grad_y = d1[i] - p_js * data[ii]
elif degree == 3:
grad_y = 0.5 * (d1[i] ** 2 - d2[i])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised that Cython doesn't optimize this directly. Did it make a significant difference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at the generated C++ and found that a ** 2 is compiled into pow(a, 2). However, it makes no difference in terms of speed. I guess the compiler inlines pow calls efficiently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no measurable speed up (which confirms my experience), I would favor the readable version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I'll revert.

Meanwhile a different win64+py2 failure appeared out of nowhere (?), I'll
try actually investigating on a windows machine.

On Tue, Jul 26, 2016 at 6:33 PM, Mathieu Blondel notifications@github.com
wrote:

In polylearn/cd_direct_fast.pyx
#1 (comment)
:

@@ -71,14 +75,14 @@ cdef inline double _update(int* indices,
if degree == 2:
grad_y = d1[i] - p_js * data[ii]
elif degree == 3:

  •        grad_y = 0.5 \* (d1[i] *\* 2 - d2[i])
    

If there's no measurable speed up (which confirms my experience), I would
favor the readable version.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/scikit-learn-contrib/polylearn/pull/1/files/49a3d7e8d41eef91ca1126b8f03b35df61b9149f..95828c13a600f1dd8395fc82fec5ad6e03a019f1#r72350574,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAOwUR53YhHcCp9XgAq9xqlTiD7Pi3yjks5qZospgaJpZM4JO8xX
.

@mblondel
Copy link
Member

Is there a way to reduce the verbosity of coveralls? I receive one email per commit, which makes it a bit difficult to follow real comments.

@vene
Copy link
Collaborator Author

vene commented Jul 26, 2016

Ok, I think I made coveralls be quiet.

@vene
Copy link
Collaborator Author

vene commented Aug 1, 2016

I fixed the windows bug! It was my fault, of course. I forgot to initialize a double scalar to 0, and it turns out this doesn't behave well on MSVC (oddly, only for py2, not for py3: must be because of the different compiler version?!)

Appveyor is green now for both win32 and win64. (I canceled a duplicate build, triggered by the fact that this branch is on scikit-learn-contrib rather than on my fork, feel free to ignore that.)

I'll remove the ugly _sq thing, update the benchmarks, then ping again for a final review before merging.

@vene vene changed the title Speedup [MRG] Speedup Aug 1, 2016
@vene
Copy link
Collaborator Author

vene commented Aug 1, 2016

This is now ready to merge.

@mblondel
Copy link
Member

mblondel commented Aug 2, 2016

I fixed the windows bug!

Hurray! Squash and merge?

@vene
Copy link
Collaborator Author

vene commented Aug 2, 2016

Merged by rebase. 🍻

@vene vene closed this Aug 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants