Conversation
|
cc @danieldk |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Still draft, noticed we actually dont want singleton but exactly the reverse |
| def __setstate__(self, state): | ||
| state, forward_func = state | ||
| self.__dict__.update(state) | ||
|
|
||
| if forward_func is not None: | ||
| # Rebind fwd set by `kernelize` to the restored instance | ||
| self.forward = MethodType(forward_func, self) | ||
|
|
||
| def __reduce__(self): | ||
| module = importlib.import_module(func.__module__) | ||
|
|
||
| # Global case => just resolve by name | ||
| if getattr(module, func.__name__, None) is self: | ||
| return func.__name__ | ||
|
|
||
| # The own private wrapper case => rebuild a separate instance and restore its state | ||
| forward_func = None | ||
| state = self.__dict__.copy() | ||
| if isinstance(forward := state.get("forward"), MethodType): | ||
| if forward.__self__ is self: | ||
| # Store the function separately and rebind it on restore | ||
| forward_func = forward.__func__ | ||
| del state["forward"] | ||
|
|
||
| return ( | ||
| _rebuild_kernel_func, | ||
| (func.__module__, func.__name__), | ||
| (state, forward_func), | ||
| ) |
There was a problem hiding this comment.
pickle is the complex case as this is just due to pickle 😅 I think we can keep it since some do use pickle but they should use safetensors
| return decorator | ||
|
|
||
|
|
||
| class CompileableContextVar: |
There was a problem hiding this comment.
it's needed for torch compile but i think there are works to make it native within dynamo, still need it for BC either way
| self.context_var.reset(token) | ||
|
|
||
|
|
||
| _ACTIVE_KERNEL_FUNCS = CompileableContextVar("_ACTIVE_KERNEL_FUNCS") |
There was a problem hiding this comment.
also let me know whether to move things to other files as im not super familiar with the repo structure I thought its simpler to just add it directly for now
As per title, we want copy/deepcopy as well as pickle to keep proper references to the actual functions. This is currently failing / losing track of the correct references. The original issue was noticed by @SunMarc see repro