Skip to content
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

Torchtyping function help strings are extremely verbose #155

Closed
neelnanda-io opened this issue Jan 26, 2023 · 4 comments
Closed

Torchtyping function help strings are extremely verbose #155

neelnanda-io opened this issue Jan 26, 2023 · 4 comments
Assignees

Comments

@neelnanda-io
Copy link
Collaborator

torchtyping used to give a function type signature is extremely verbose when printing the type, to somewhat ridiculous extents. Eg, here is model.run_with_cache?:

Signature:
model.run_with_cache(
    *model_args,
    return_cache_object=True,
    remove_batch_dim=False,
    **kwargs,
) -> Tuple[Union[NoneType, typing_extensions.Annotated[torch.Tensor, {'__torchtyping__': True, 'details': ('batch', 'pos', 'd_vocab',), 'cls_name': 'TensorType'}], typing_extensions.Annotated[torch.Tensor, {'__torchtyping__': True, 'details': ((),), 'cls_name': 'TensorType'}], typing_extensions.Annotated[torch.Tensor, {'__torchtyping__': True, 'details': ('batch', 'position - 1',), 'cls_name': 'TensorType'}], Tuple[typing_extensions.Annotated[torch.Tensor, {'__torchtyping__': True, 'details': ('batch', 'pos', 'd_vocab',), 'cls_name': 'TensorType'}], Union[typing_extensions.Annotated[torch.Tensor, {'__torchtyping__': True, 'details': ((),), 'cls_name': 'TensorType'}], typing_extensions.Annotated[torch.Tensor, {'__torchtyping__': True, 'details': ('batch', 'position - 1',), 'cls_name': 'TensorType'}]]]], Union[transformer_lens.ActivationCache.ActivationCache, Dict[str, torch.Tensor]]]
Docstring: Wrapper around run_with_cache in HookedRootModule. If return_cache_object is True, this will return an ActivationCache object, with a bunch of useful HookedTransformer specific methods, otherwise it will return a dictionary of activations as in HookedRootModule.
@neelnanda-io
Copy link
Collaborator Author

@alan-cooney thoughts?

@alan-cooney
Copy link
Collaborator

Yeah it's a bit of a pain - no obvious solutions unfortunately.

Could be worth creating an issue at https://github.com/patrick-kidger/torchtyping if you're running into this a lot? I'm not sure how common it is to print out type signatures like this

@alan-cooney
Copy link
Collaborator

Torchtyping is now encouraging use of https://github.com/google/jaxtyping instead, so this may solve this as well

@jbloomAus
Copy link
Collaborator

Seems like this is probably achieved by 164. Can reopen if we notice it's still an issue. I think when formatted nicely, it's probably worth having the typing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants