dmlc / minpy

NumPy interface with mixed backend execution

Home Page:https://minpy.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'module' object has no attribute 'OnlyNumPyPolicy'

jacklxc opened this issue · comments

I just updated MXNet and Minpy to the latest version, and the following code worked previously but does not work anymore.
import minpy
minpy.set_global_policy(minpy.OnlyNumPyPolicy())

The error is 'module' object has no attribute 'OnlyNumPyPolicy'. How do I fix this problem?

Thank you.

It seems latest documentation's code does not work for me. Same problems exists.

When I try
import minpy.numpy as np
from minpy import OnlyNumPyPolicy
np.set_policy(OnlyNumPyPolicy()),
There is error that ImportError: cannot import name OnlyNumPyPolicy.

@jacklxc Could you try
import minpy
dir(minpy)
in an interpreter and check whether OnlyNumpyPolicy appears in the output list?

@GaiYu0 'PreferMXNetPolicy' appears but there is no OnlyNumpyPolicy. These two classes are in the same file policy.py with the same format, but I don't know why only one of them is in the path.

I have to use OnlyNumPyPolicy() to prevent further error. Everything was fine before I updated MXNet and Minpy. Now the packages such as minpy.numpy work properly. I am not sure if this issue is because of the change made in minpy, or my local change.

I encountered many frustrating bug before I used OnlyNumpyPolicy(). For example the first error when I remove the policy is

ValueError                                Traceback (most recent call last)
<ipython-input-3-f823b5e89bd5> in <module>()
----> 1 model = SimplePolicyNetwork(hidden_dim=5,reg=0)

/Users/lixiangci/Google Drive/GitHub_codes/VirtualRat/SimplePolicyNetwork.pyc in __init__(self, N, input_dim, hidden_dim, output_dim, gamma, reg)
     15         # Initialize h0
     16         self.h0 = np.random.randn(N, hidden_dim)
---> 17         self.h0 /= np.sqrt(N)
     18         self.h = self.h0
     19 

/Users/lixiangci/minpy/minpy/primitive.pyc in __call__(self, *args, **kwargs)
    132     def __call__(self, *args, **kwargs):
    133         """Wrap args for `call` method."""
--> 134         return self.call(args, kwargs)
    135 
    136     def _convert_data(self, data, mutate):

/Users/lixiangci/minpy/minpy/primitive.pyc in call(self, args, kwargs)
    219         if self.type == ArrayType.MXNET:
    220             with context.current_context().as_mxnet_context():
--> 221                 result_value = self._func(*arg_values, **kwarg_values)
    222         else:
    223             result_value = self._func(*arg_values, **kwarg_values)

/Users/lixiangci/mxnet/python/mxnet/_ctypes/ndarray.pyc in generic_ndarray_function(*args, **kwargs)
    102 
    103         if len(pos_args) > len(arguments):
--> 104             raise ValueError("Too many positional arguments")
    105         kwargs.update(zip(arguments[:len(pos_args)], pos_args))
    106         if 'dtype' in kwargs:

ValueError: Too many positional arguments

Personally I suggest to give users more choice.

OK, I see.
Could you raise another PR for this bug? It would be helpful if you can paste the minimum reproduce code snippet. Thank you!

Sorry, this error is due to the recent change in policy interface. I will update the doc and example. To enable numpy only policy. Try:

import minpy
minpy.set_global_policy('only_numpy')

or

import minpy
minpy.set_global_policy(minpy.dispatch.policy.OnlyNumPyPolicy())

The changes are:

  • We do not allow per-module policy switch (e.g. different policy for numpy and numpy.random modules)
  • It is undefined behavior to switch policy in the middle of your code. It is suggested to set the global policy at the beginning of your code, before any minpy APIs are called.

The document will be updated soon. Sorry for the inconvenience.

It seems that documentation is already updated.