Skip to content

Commit

Permalink
Rest of the model refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
LysandreJik committed Sep 6, 2024
1 parent 3967eaa commit e3665de
Show file tree
Hide file tree
Showing 1,144 changed files with 6,381 additions and 15,589 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
command: pip freeze | tee installed.txt
- store_artifacts:
path: ~/transformers/installed.txt
- run: python -c "from transformers import *" || (echo '🚨 import failed, this means you introduced unprotected imports! 🚨'; exit 1)
- run: python -c "from transformers import *" || (echo '🚨 import failed, this means you introduced unprotected imports! Have you added this object to the __all__ object of the module? 🚨'; exit 1)
- run: ruff check examples tests src utils
- run: ruff format tests src utils --check
- run: python utils/custom_init_isort.py --check_only
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repo-consistency:
# this target runs checks on all files

quality:
@python -c "from transformers import *" || (echo '🚨 import failed, this means you introduced unprotected imports! 🚨'; exit 1)
@python -c "from transformers import *" || (echo '🚨 import failed, this means you introduced unprotected imports! Have you added this object to the __all__ object of the module? 🚨'; exit 1)
ruff check $(check_dirs) setup.py conftest.py
ruff format --check $(check_dirs) setup.py conftest.py
python utils/sort_auto_mappings.py --check_only
Expand Down
45 changes: 7 additions & 38 deletions src/transformers/models/audio_spectrogram_transformer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,16 @@
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_import_structure = {
"configuration_audio_spectrogram_transformer": ["ASTConfig"],
"feature_extraction_audio_spectrogram_transformer": ["ASTFeatureExtractor"],
}

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_audio_spectrogram_transformer"] = [
"ASTForAudioClassification",
"ASTModel",
"ASTPreTrainedModel",
]
from ...utils import _LazyModule
from ...utils.import_utils import define_import_structure


if TYPE_CHECKING:
from .configuration_audio_spectrogram_transformer import (
ASTConfig,
)
from .feature_extraction_audio_spectrogram_transformer import ASTFeatureExtractor

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_audio_spectrogram_transformer import (
ASTForAudioClassification,
ASTModel,
ASTPreTrainedModel,
)


from .configuration_audio_spectrogram_transformer import *
from .feature_extraction_audio_spectrogram_transformer import *
from .modeling_audio_spectrogram_transformer import *
else:
import sys

sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
_file = globals()["__file__"]
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,6 @@ def __init__(
# generative parameters deprecation cycle, overwriting this function prevents this from happening.
def _get_non_default_generation_parameters(self) -> Dict[str, Any]:
return {}


__all__ = ["ASTConfig"]
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,6 @@ def __call__(
padded_inputs = padded_inputs.convert_to_tensors(return_tensors)

return padded_inputs


__all__ = ["ASTFeatureExtractor"]
Original file line number Diff line number Diff line change
Expand Up @@ -654,3 +654,6 @@ def forward(
hidden_states=outputs.hidden_states,
attentions=outputs.attentions,
)


__all__ = ["ASTPreTrainedModel", "ASTModel", "ASTForAudioClassification"]
42 changes: 6 additions & 36 deletions src/transformers/models/autoformer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,15 @@
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_import_structure = {
"configuration_autoformer": ["AutoformerConfig"],
}

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_autoformer"] = [
"AutoformerForPrediction",
"AutoformerModel",
"AutoformerPreTrainedModel",
]
from ...utils import _LazyModule
from ...utils.import_utils import define_import_structure


if TYPE_CHECKING:
from .configuration_autoformer import (
AutoformerConfig,
)

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_autoformer import (
AutoformerForPrediction,
AutoformerModel,
AutoformerPreTrainedModel,
)

from .configuration_autoformer import *
from .modeling_autoformer import *
else:
import sys

sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
_file = globals()["__file__"]
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,6 @@ def _number_of_features(self) -> int:
+ self.num_static_real_features
+ self.input_size * 2 # the log1p(abs(loc)) and log(scale) features
)


__all__ = ["AutoformerConfig"]
3 changes: 3 additions & 0 deletions src/transformers/models/autoformer/modeling_autoformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2150,3 +2150,6 @@ def generate(
(-1, num_parallel_samples, self.config.prediction_length) + self.target_shape,
)
)


__all__ = ["AutoformerPreTrainedModel", "AutoformerModel", "AutoformerForPrediction"]
61 changes: 7 additions & 54 deletions src/transformers/models/bark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,16 @@
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_torch_available,
)
from ...utils import _LazyModule
from ...utils.import_utils import define_import_structure


_import_structure = {
"configuration_bark": [
"BarkCoarseConfig",
"BarkConfig",
"BarkFineConfig",
"BarkSemanticConfig",
],
"processing_bark": ["BarkProcessor"],
}

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_bark"] = [
"BarkFineModel",
"BarkSemanticModel",
"BarkCoarseModel",
"BarkModel",
"BarkPreTrainedModel",
"BarkCausalModel",
]

if TYPE_CHECKING:
from .configuration_bark import (
BarkCoarseConfig,
BarkConfig,
BarkFineConfig,
BarkSemanticConfig,
)
from .processing_bark import BarkProcessor

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_bark import (
BarkCausalModel,
BarkCoarseModel,
BarkFineModel,
BarkModel,
BarkPreTrainedModel,
BarkSemanticModel,
)

from .configuration_bark import *
from .modeling_bark import *
from .processing_bark import *
else:
import sys

sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
_file = globals()["__file__"]
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
3 changes: 3 additions & 0 deletions src/transformers/models/bark/configuration_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,6 @@ def from_sub_model_configs(
codec_config=codec_config.to_dict(),
**kwargs,
)


__all__ = ["BarkSemanticConfig", "BarkCoarseConfig", "BarkFineConfig", "BarkConfig"]
12 changes: 12 additions & 0 deletions src/transformers/models/bark/modeling_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ def device(self) -> torch.device:


# GPT2-like autoregressive model


class BarkCausalModel(BarkPreTrainedModel):
config_class = BarkSubModelConfig

Expand Down Expand Up @@ -1811,3 +1813,13 @@ def _check_and_enable_flash_attn_2(
config.coarse_acoustics_config._attn_implementation = config._attn_implementation
config.fine_acoustics_config._attn_implementation = config._attn_implementation
return config


__all__ = [
"BarkPreTrainedModel",
"BarkCausalModel",
"BarkFineModel",
"BarkCoarseModel",
"BarkSemanticModel",
"BarkModel",
]
3 changes: 3 additions & 0 deletions src/transformers/models/bark/processing_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,6 @@ def __call__(
encoded_text["history_prompt"] = voice_preset

return encoded_text


__all__ = ["BarkProcessor"]
Loading

0 comments on commit e3665de

Please sign in to comment.