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

Modular files #35515

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 6 additions & 36 deletions src/transformers/models/granite/__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

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


_import_structure = {
"configuration_granite": ["GraniteConfig"],
}

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_granite"] = [
"GraniteForCausalLM",
"GraniteModel",
"GranitePreTrainedModel",
]

if TYPE_CHECKING:
from .configuration_granite import GraniteConfig

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_granite import (
GraniteForCausalLM,
GraniteModel,
GranitePreTrainedModel,
)

from .modeling_granite import *
from .configuration_granite 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/granite/configuration_granite.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,6 @@ def __init__(
)

rope_config_validation(self)


__all__ = ['GraniteConfig']
3 changes: 3 additions & 0 deletions src/transformers/models/granite/modeling_granite.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,6 @@ def forward(
hidden_states=outputs.hidden_states,
attentions=outputs.attentions,
)


__all__ = ['GraniteForCausalLM', 'GraniteModel', 'GranitePreTrainedModel']
72 changes: 9 additions & 63 deletions src/transformers/models/instructblipvideo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 The HuggingFace Team. All rights reserved.
# Copyright 2025 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,71 +13,17 @@
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available
from ...utils import _LazyModule
from ...utils.import_utils import define_import_structure


_import_structure = {
"configuration_instructblipvideo": [
"InstructBlipVideoConfig",
"InstructBlipVideoQFormerConfig",
"InstructBlipVideoVisionConfig",
],
"processing_instructblipvideo": ["InstructBlipVideoProcessor"],
}


try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["image_processing_instructblipvideo"] = ["InstructBlipVideoImageProcessor"]


try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_instructblipvideo"] = [
"InstructBlipVideoQFormerModel",
"InstructBlipVideoPreTrainedModel",
"InstructBlipVideoForConditionalGeneration",
"InstructBlipVideoVisionModel",
]

if TYPE_CHECKING:
from .configuration_instructblipvideo import (
InstructBlipVideoConfig,
InstructBlipVideoQFormerConfig,
InstructBlipVideoVisionConfig,
)
from .processing_instructblipvideo import InstructBlipVideoProcessor

try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .image_processing_instructblipvideo import InstructBlipVideoImageProcessor

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_instructblipvideo import (
InstructBlipVideoForConditionalGeneration,
InstructBlipVideoPreTrainedModel,
InstructBlipVideoQFormerModel,
InstructBlipVideoVisionModel,
)

from .modeling_instructblipvideo import *
from .processing_instructblipvideo import *
from .configuration_instructblipvideo import *
from .image_processing_instructblipvideo 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 @@ -340,3 +340,6 @@ def from_vision_qformer_text_configs(
text_config=text_config.to_dict(),
**kwargs,
)


__all__ = ['InstructBlipVideoConfig', 'InstructBlipVideoQFormerConfig', 'InstructBlipVideoVisionConfig']
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,6 @@ def _preprocess_image(
image = to_channel_dimension_format(image, data_format, input_channel_dim=input_data_format)

return image


__all__ = ['InstructBlipVideoImageProcessor']
Original file line number Diff line number Diff line change
Expand Up @@ -1668,3 +1668,6 @@ def generate(
outputs = self.language_model.generate(**inputs, **generate_kwargs)

return outputs


__all__ = ['InstructBlipVideoQFormerModel', 'InstructBlipVideoPreTrainedModel', 'InstructBlipVideoForConditionalGeneration', 'InstructBlipVideoVisionModel']
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,6 @@ def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
qformer_tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path, subfolder="qformer_tokenizer")
processor.qformer_tokenizer = qformer_tokenizer
return processor


__all__ = ['InstructBlipVideoProcessor']
107 changes: 9 additions & 98 deletions src/transformers/models/mistral/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Mistral AI and The HuggingFace Inc. team. All rights reserved.
# Copyright 2025 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,106 +13,17 @@
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_flax_available,
is_tf_available,
is_torch_available,
)


_import_structure = {
"configuration_mistral": ["MistralConfig"],
}


try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_mistral"] = [
"MistralForCausalLM",
"MistralForQuestionAnswering",
"MistralModel",
"MistralPreTrainedModel",
"MistralForSequenceClassification",
"MistralForTokenClassification",
]

try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_mistral"] = [
"FlaxMistralForCausalLM",
"FlaxMistralModel",
"FlaxMistralPreTrainedModel",
]

try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_mistral"] = [
"TFMistralModel",
"TFMistralForCausalLM",
"TFMistralForSequenceClassification",
"TFMistralPreTrainedModel",
]
from ...utils import _LazyModule
from ...utils.import_utils import define_import_structure


if TYPE_CHECKING:
from .configuration_mistral import MistralConfig

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_mistral import (
MistralForCausalLM,
MistralForQuestionAnswering,
MistralForSequenceClassification,
MistralForTokenClassification,
MistralModel,
MistralPreTrainedModel,
)

try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_mistral import (
FlaxMistralForCausalLM,
FlaxMistralModel,
FlaxMistralPreTrainedModel,
)

try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_mistral import (
TFMistralForCausalLM,
TFMistralForSequenceClassification,
TFMistralModel,
TFMistralPreTrainedModel,
)


from .modeling_tf_mistral import *
from .modeling_flax_mistral import *
from .configuration_mistral import *
from .modeling_mistral 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/mistral/configuration_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ def __init__(
tie_word_embeddings=tie_word_embeddings,
**kwargs,
)


__all__ = ['MistralConfig']
3 changes: 3 additions & 0 deletions src/transformers/models/mistral/modeling_flax_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,6 @@ def update_inputs_for_generation(self, model_outputs, model_kwargs):
_CONFIG_FOR_DOC,
real_checkpoint=_REAL_CHECKPOINT_FOR_DOC,
)


__all__ = ['FlaxMistralForCausalLM', 'FlaxMistralModel', 'FlaxMistralPreTrainedModel']
3 changes: 3 additions & 0 deletions src/transformers/models/mistral/modeling_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,3 +1146,6 @@ def forward(
hidden_states=outputs.hidden_states,
attentions=outputs.attentions,
)


__all__ = ['MistralForCausalLM', 'MistralForQuestionAnswering', 'MistralModel', 'MistralPreTrainedModel', 'MistralForSequenceClassification', 'MistralForTokenClassification']
3 changes: 3 additions & 0 deletions src/transformers/models/mistral/modeling_tf_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,3 +1052,6 @@ def build(self, input_shape=None):
if getattr(self, "score", None) is not None:
with tf.name_scope(self.score.name):
self.score.build((self.config.hidden_size,))


__all__ = ['TFMistralModel', 'TFMistralForCausalLM', 'TFMistralForSequenceClassification', 'TFMistralPreTrainedModel']
Loading
Loading