-
Notifications
You must be signed in to change notification settings - Fork 54
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
Bug: loading certain scipy functions fails #184
Comments
In the code that @BenjaminBossan has given, the core of the error seems to come from serialising a bound method of an instance of the I tried just adding "method" as a special case in the Basically, I think it's not serialising enough information for bound methods. As you can see in your state, the "pyfunc" is just a "method", but it doesn't at all say what it is a method of. It should be serialising the object (here: an instance of |
I can confirm that adding dummy I'll raise a draft PR that has the code needed to get the above example working, but I think it'll need more work to make sure it works in other cases of bound methods getting serialised. |
Draft PR above ^ shows the fix for this, still needs a bit of work before I raise the full PR but it's there if you want to check the fix :) |
Besides the problem with methods, there is also a problem with circular references. Here are some simple examples that fail at the moment: class ObjWithCircularRef:
def __init__(self):
self.x = [123]
self.y = {"a": self.x}
self.x.append(self.y)
class ObjWithCircularRef:
def __init__(self):
self.x = [123, self, 456] Fixing this might also fix |
Reopening since this is not fixed IIUC. |
Yep, bug still exists, but for a different reason now. We can now persist methods in general, but circular references (as exist in |
Jumping back on this once I've merged in #209 |
So I've looked at how Pickle handles this type of problem, and I think I understand their method. The main takeaway is this: In addition to a memo, Pickle's implementation creates a stack of objects and opcodes during dump and load. This comes with a few benefits, but for this issue in particular, the main benefit is that it allows Pickle to Link to part of the pickle source code that shows this with a comment Link to part of the pickletools documentation describing the purpose of I also came up with a minimal reproduction of the error:
You can also use the pickletools To implement a stack like For the issue referenced originally, there's likely a much simpler workaround we could implement, but I also think having some a stack implementation would be a good idea to consider for a more general fix. |
Could you try the code from #204 ? For me your test doesn't fail, but I haven't tested if the loaded object is actually valid. |
It's probably a bug in the pasted code, where the variable
Yes, we explicitly didn't want to "re-invent" the whole pickle machinery, at that point we might as well use pickle :) So hopefully, for the much narrower scope we set ourselves for skops, we find a way to avoid this problem. Absolute worst case scenario would be special casing objects known to have that problem and giving custom code an escape hatch via |
Ah yep, I tried to combine two tests but forgot to rename the variables, my bad! I can double check it still fails on #204 this eve |
Hi, I think I'm getting the same error when trying to serialise a keras model:
Just posting in case it's helpful to anyone else and/or helps with the bug fixing! |
@blaisethom Thanks for reporting. Please note that keras is not supported at the moment, so I wouldn't expect it to work. |
@blaisethom have you tried with |
Hi, @adrinjalali - yes, I realised after posting that I should have done that and did so but it gives the same error. |
@blaisethom if you're kind enough to open a new issue with a mini reproducible it'd be very helpful |
Done |
Certain scipy functions cannot be loaded correctly. Here is a test to reproduce:
zipf
is only one of a few failing scipy functions that I tested. The error message iswith a really long, unhelpful stacktrace. However, the problem already occurs during the generation of the
state
, which looks really weird:Click to expand
(
"key_types"
omitted for readability)The text was updated successfully, but these errors were encountered: