Replies: 2 comments
-
|
It sounds interesting! Would you be willing to contribute such a feature? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I did some research on this and found that python actually has a feature exactly for this purpose, what I asked can be done with: m.def("__getattr__", [&](nb::handle key) -> nb::object {
if (nb::isinstance<nb::str>(key) && nb::cast<std::string>(key) == "state") {
return state;
}
return nb::steal(PyErr_Format(
PyExc_AttributeError,
"Module 'random' has no attribute %R",
key.ptr()));
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We need a way to lazily initialized module attributes, i.e.
def_propfor modules, there are 2 use cases in MLX:mx.random.stateat import time (to avoid initializing GPU too early).mx.random.statea thread-local variable (to support multi-threads).Beta Was this translation helpful? Give feedback.
All reactions