You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Object of type "InterventionProxy" cannot be used with "with" because it does not implement __enter__
Attribute "__enter__" is unknown
Object of type "InterventionProxy" cannot be used with "with" because it does not implement __exit__
It looks like this because LanguageModel.__new__() is typed as returning either a LanguageModel or an Envoy. Envoy.__call__() returns an InterventionProxy, which is not a contextmanager. Since the type checker doesn't know if the model is a LanguageModel or an Envoy, it has to assume that model might be an Envoy and thus can't use with model.trace() as a contextmanager. It seems like __new__() should be typed to just return a LanguageModel, no?
The text was updated successfully, but these errors were encountered:
@chanind Would you mind trying this on the 0.4 branch and let me know if it still complains? pip install --upgrade git+https://github.com/ndif-team/[email protected] If so I'll take a closer look.
In general though, I am doing very weird things with typing... this is because I have a lot of objects (like NNsight, Envoy, and Proxies) that represent other types of objects (Huggingface models, torch modules, and tensors respectively) but aren't themselves those objects. So I would like you IDE to still be able to complete/hint at methods/attributes on their "wrapper" objects. If you have any thoughts on this I'd love to hear them!
The following code works, but pyright/pylance gives a typing error:
The errors are the following:
It looks like this because
LanguageModel.__new__()
is typed as returning either aLanguageModel
or anEnvoy
.Envoy.__call__()
returns anInterventionProxy
, which is not a contextmanager. Since the type checker doesn't know if the model is aLanguageModel
or anEnvoy
, it has to assume thatmodel
might be anEnvoy
and thus can't usewith model.trace()
as a contextmanager. It seems like__new__()
should be typed to just return aLanguageModel
, no?The text was updated successfully, but these errors were encountered: