New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion to fix the TypeError issue #994 on Windows. #1550
Conversation
Errors occurs because some ndarrays with dtype=int32 are passed to the function delta_logp which expects ndarrays with dtype=int64 as inputs. Inputs are casted with `ndarray.astype(int)`, but on Windows, the Python 'int' type is treated as a 32-bit integer by NumPy. I suggest to remove the line with `f.trust_input = True` to ensure that Theano always checks the inputs and casts it if necessary and when possible. This fix resolves the issue on my computer: ``` Python version: 2.7.12 |Continuum Analytics, Inc.| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] OS version: Windows-8.1-6.3.9600 ```
I think we set |
What happens if you do |
I would prefer your option 1 I think. |
Just a comment. For efficiency, I think option 1 should be done. That way
only 1 cast will be done. Only not using trust input will make Theano cast
the input again at the start of the function if the dtype isn't the right
one.
But I would also remove the trust_input except if it give super big speed
up. Don't forget, it took 9 mounts to find that problem in pymc3. So is the
speed up worth the debugging trouble?
…On Fri, Nov 25, 2016 at 8:10 AM, Thomas Wiecki ***@***.***> wrote:
I would prefer your option 1 I think.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1550 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AALC-4Dh6hr3tRjFFH9D901mBhbfzZFsks5rBt47gaJpZM4K7-7K>
.
|
@nouiz You do have a point. Perhaps we make this configurable and default to False. |
@nouiz I suppose there is no flag which would have ensured that the dtypes are correctly passed. I.e. not casting automatically if it's the wrong dtype, but raising an error. |
exact. Could be a nice feature request, but it isn't existing.
…On Fri, Nov 25, 2016 at 9:09 AM, Thomas Wiecki ***@***.***> wrote:
@nouiz <https://github.com/nouiz> I suppose there is no flag which would
have ensured that the dtypes are correctly passed. I.e. not casting
automatically if it's the wrong dtype, but raising an error.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1550 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AALC--CQVAgCZSSDaEph5zZ0qFQVdl1iks5rBuv9gaJpZM4K7-7K>
.
|
Hello! Aftter further investigations related to solution 1 (casting
But the dtype of Discrete instances can be changed, and therefore, if an user does not use For example, currently (with trust_input removed but q and q0 not yet casted), the example code works, but if I replace:
with
Then I got the following error:
I suggest to hold the dtype of Discrete classes to Other modifications still include to remove trust_input, and to cast q and q0 to int64 only when Metropolis handles a Discrete model. Could it be a good solution, @twiecki ? |
PS: Perhaps the dtype of Continuous classes (float64) should also be forced (with a TypeError raised if any other dtype is specified) ? |
Yes, I think that's the right solution here. Do you want to implement that? In regards to float64 -- I think forcing that would not allow PyMC3 to run on the GPU which requires float32 to be used. See #1338. However, we could just check that the dtype matches to whatever default we want to use (and perhaps automatically cast it). |
Arguments for delta_logp in Metropolis.astep() are now casted to 'int64' when Metropolis handles a discrete model.
@twiecki Ok ! So I just update the PR with int64 corrections only. Updated. |
Thanks @notoraptor! |
* Suggestion to fix the TypeError issue pymc-devs#994 on Windows. Errors occurs because some ndarrays with dtype=int32 are passed to the function delta_logp which expects ndarrays with dtype=int64 as inputs. Inputs are casted with `ndarray.astype(int)`, but on Windows, the Python 'int' type is treated as a 32-bit integer by NumPy. I suggest to remove the line with `f.trust_input = True` to ensure that Theano always checks the inputs and casts it if necessary and when possible. This fix resolves the issue on my computer: ``` Python version: 2.7.12 |Continuum Analytics, Inc.| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] OS version: Windows-8.1-6.3.9600 ``` * Discrete super-class raises TypeError if dtype != 'int64'. Arguments for delta_logp in Metropolis.astep() are now casted to 'int64' when Metropolis handles a discrete model.
* Suggestion to fix the TypeError issue pymc-devs#994 on Windows. Errors occurs because some ndarrays with dtype=int32 are passed to the function delta_logp which expects ndarrays with dtype=int64 as inputs. Inputs are casted with `ndarray.astype(int)`, but on Windows, the Python 'int' type is treated as a 32-bit integer by NumPy. I suggest to remove the line with `f.trust_input = True` to ensure that Theano always checks the inputs and casts it if necessary and when possible. This fix resolves the issue on my computer: ``` Python version: 2.7.12 |Continuum Analytics, Inc.| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] OS version: Windows-8.1-6.3.9600 ``` * Discrete super-class raises TypeError if dtype != 'int64'. Arguments for delta_logp in Metropolis.astep() are now casted to 'int64' when Metropolis handles a discrete model.
Hello ! This is a working suggestion (and some remarks) to fix the issue 994 related to theano TypeError #994 .
I fixed the issue on my computer (Python
2.7.12 |Continuum Analytics, Inc.| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)]
, OSWindows-8.1-6.3.9600
). As test code, I extracted the python code from the notebook of @napsternxg : https://gist.github.com/notoraptor/75fd0db142a21710a11b7a2e17f38cbaAfter further investigations, I found that the error comes from 2 problems.
First, the pymc3 function
delta_logp
, which is in fact a theano function, expects int64 arrays as input, but receives int32 arrays on Windows. These arrays areq
andq0
passed here: https://github.com/pymc-devs/pymc3/blob/master/pymc3/step_methods/metropolis.py#L124 :q
andq0
are casted in previous lines with.astype(int)
, but on Windows, the Python typeint
is treated as an int32 by NumPy.The second problem is in the function
delta_logp
. When it generates the associated theano function, it deactivates the input verification done in Theano by settingtrust_input
to true: https://github.com/pymc-devs/pymc3/blob/master/pymc3/step_methods/metropolis.py#L434As mentionned in theano documentation: https://github.com/Theano/Theano/blob/master/theano/compile/function_module.py
Therefore, it is the C code that returns the TypeError when it detects the int32 vs int64 mismatch.
So, there is two solutions: either cast explicitely
q
andq0
to int64, or remove the line withf.trust_input = True
in functiondelta_logp
. In this pull request I suggest the later solution, as the type of the inputs ofdelta_logp
does not seem easy to guarantee in any case (that is, is it always int64?).@nouiz @lamblin !