Skip to content

Conversation

@ringohoffman
Copy link

@ringohoffman ringohoffman commented Dec 2, 2022

What does this PR do?

This PR generally adds type hints for the files located at src/transformers/models/esm/openfold_utils/.

  1. add function/method parameter type hints where missing; add type info on collections
  2. export dict_multimap, flatten_final_dims, permute_final_dims in __init__.py since these functions are currently duplicated in src/transformers/models/esm/modeling_esmfold.py; exporting these from openfold_utils should allow us to remove these duplicates
  3. refactor type(x) is y to use the builtin isinstance(x, y)
  4. refactor to avoid reassignment to the same variable with a different type (this is frowned upon by type checkers) by using multiple variables / combining expressions to avoid reassignment
  5. add assert statements to to narrow types
  6. add a FIXME statement at an apparent bug in protein.py in which string mutation is attempted
  7. various minor refactors

Related: #16059

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).

Who can review?

@Rocketknight1

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Dec 2, 2022

The documentation is not available anymore as the PR was closed or merged.

@Rocketknight1
Copy link
Member

Wow, this is really comprehensive! All of your edits seem good, and thanks for catching those duplicate functions!

The code is failing some of our code style checks, but I believe I can fix that for you, hang on!

@Rocketknight1
Copy link
Member

I think the other issues are just old issues with our repo - they'll be fixed if you pull from upstream on your fork's main branch in the GitHub UI and then rebase your branch onto that, followed by a force push

Matthew Hoffman and others added 9 commits December 2, 2022 11:11
use isinstance builtin instead of 'type(x) is y'; add assertions to aid in type inferencing; use bools instead of ints in _get_minimal_slice_set for improved type clarity; refactor to avoid re-assigning to the same variable with a different type
refactor to avoid re-assigning to the same variable with a different type
refactor to avoid re-assigning to the same variable with a different type
refactor to avoid re-assigning to the same variable with a different type; fix Callable, Tuple type hints; match conditional structure to other methods; fix return type on Rotation.cat and Rotation.unsqueeze
overload for tree_map; use insinstance builtin instead of 'type(x) is y'; export dict_multimap, flatten_final_dims, permute_final_dims in openfold_utils
add FIXME for attempted string mutation; add missing None check in get_pdb_headers; fix potentially unbound variable 'chain_tag' in to_pdb; modify get_pdb_headers return type
hints on collection constants; remove magic trailing comma to reduce number of lines; change list -> tuple for rigid_group_atom_positions for improved hinting
@Rocketknight1
Copy link
Member

@ringohoffman Looks good to me now! Are you okay with me merging it?

@ringohoffman
Copy link
Author

@ringohoffman Looks good to me now! Are you okay with me merging it?

I'm good if you are!

@Rocketknight1 Rocketknight1 merged commit afe2a46 into huggingface:main Dec 5, 2022
@ringohoffman ringohoffman deleted the esm_type_hints branch December 5, 2022 16:51
mpierrau pushed a commit to mpierrau/transformers that referenced this pull request Dec 15, 2022
* add type annotations for esm chunk_utils

use isinstance builtin instead of 'type(x) is y'; add assertions to aid in type inferencing; use bools instead of ints in _get_minimal_slice_set for improved type clarity; refactor to avoid re-assigning to the same variable with a different type

* add type annotations for esm data_transforms

refactor to avoid re-assigning to the same variable with a different type

* add type annotations for esm feats utils

refactor to avoid re-assigning to the same variable with a different type

* add type annotations for esm loss utils

* add/fix type annotations for esm rigit_utils

refactor to avoid re-assigning to the same variable with a different type; fix Callable, Tuple type hints; match conditional structure to other methods; fix return type on Rotation.cat and Rotation.unsqueeze

* add type annotations for esm tensor_utils

overload for tree_map; use insinstance builtin instead of 'type(x) is y'; export dict_multimap, flatten_final_dims, permute_final_dims in openfold_utils

* add type annotations for esm protein utils

add FIXME for attempted string mutation; add missing None check in get_pdb_headers; fix potentially unbound variable 'chain_tag' in to_pdb; modify get_pdb_headers return type

* add type annotations for esm residue constants

hints on collection constants; remove magic trailing comma to reduce number of lines; change list -> tuple for rigid_group_atom_positions for improved hinting

* code style fixup

Co-authored-by: Matt <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants