Skip to content
Merged
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
4 changes: 0 additions & 4 deletions docs/source/en/internal/file_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ Most of those are only useful if you are studying the general code in the librar

[[autodoc]] utils.replace_return_docstrings

## Special Properties

[[autodoc]] utils.cached_property

## Other Utilities

[[autodoc]] utils._LazyModule
Expand Down
4 changes: 0 additions & 4 deletions docs/source/ja/internal/file_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ rendered properly in your Markdown viewer.

[[autodoc]] utils.replace_return_docstrings

## 特殊なプロパティ

[[autodoc]] utils.cached_property

## その他のユーティリティ

[[autodoc]] utils._LazyModule
4 changes: 0 additions & 4 deletions docs/source/ko/internal/file_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ rendered properly in your Markdown viewer.

[[autodoc]] utils.replace_return_docstrings

## 특수 속성 (Special Properties) [[transformers.utils.cached_property]]

[[autodoc]] utils.cached_property

## 기타 유틸리티 [[transformers.utils._LazyModule]]

[[autodoc]] utils._LazyModule
5 changes: 0 additions & 5 deletions docs/source/zh/internal/file_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ rendered properly in your Markdown viewer.

其中大多数仅在您研究库中的通用代码时才有用。


## Enums和namedtuples(命名元组)

[[autodoc]] utils.ExplicitEnum
Expand All @@ -41,10 +40,6 @@ rendered properly in your Markdown viewer.

[[autodoc]] utils.replace_return_docstrings

## 特殊的属性

[[autodoc]] utils.cached_property

## 其他实用程序

[[autodoc]] utils._LazyModule
1 change: 0 additions & 1 deletion src/transformers/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
add_end_docstrings,
add_start_docstrings,
add_start_docstrings_to_model_forward,
cached_property,
copy_func,
default_cache_path,
define_sagemaker_information,
Expand Down
3 changes: 2 additions & 1 deletion src/transformers/sagemaker/training_args_sm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import os
import warnings
from dataclasses import dataclass, field
from functools import cached_property

import torch

from ..training_args import TrainingArguments
from ..utils import cached_property, is_sagemaker_dp_enabled, logging
from ..utils import is_sagemaker_dp_enabled, logging


logger = logging.get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/training_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from dataclasses import asdict, dataclass, field, fields
from datetime import timedelta
from enum import Enum
from functools import cached_property
from pathlib import Path
from typing import Any, Optional, Union

Expand All @@ -37,7 +38,6 @@
from .utils import (
ACCELERATE_MIN_VERSION,
ExplicitEnum,
cached_property,
is_accelerate_available,
is_apex_available,
is_ipex_available,
Expand Down
3 changes: 2 additions & 1 deletion src/transformers/training_args_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

import warnings
from dataclasses import dataclass, field
from functools import cached_property
from typing import Optional

from .training_args import TrainingArguments
from .utils import cached_property, is_tf_available, logging, requires_backends
from .utils import is_tf_available, logging, requires_backends


logger = logging.get_logger(__name__)
Expand Down
1 change: 0 additions & 1 deletion src/transformers/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
PaddingStrategy,
TensorType,
TransformersKwargs,
cached_property,
can_return_loss,
can_return_tuple,
expand_dims,
Expand Down
23 changes: 0 additions & 23 deletions src/transformers/utils/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,6 @@
from ..model_debugging_utils import model_addition_debugger_context


class cached_property(property):
"""
Descriptor that mimics @property but caches output in member variable.

From tensorflow_datasets

Built-in in functools from Python 3.8.
"""

def __get__(self, obj, objtype=None):
# See docs.python.org/3/howto/descriptor.html#properties
if obj is None:
return self
if self.fget is None:
raise AttributeError("unreadable attribute")
attr = "__cached_" + self.fget.__name__
cached = getattr(obj, attr, None)
if cached is None:
cached = self.fget(obj)
setattr(obj, attr, cached)
return cached


# vendored from distutils.util
def strtobool(val):
"""Convert a string representation of truth to true (1) or false (0).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

import inspect
import unittest
from functools import cached_property

from huggingface_hub import hf_hub_download

from transformers import ASTConfig
from transformers.testing_utils import require_torch, require_torchaudio, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_torchaudio_available
from transformers.utils import is_torch_available, is_torchaudio_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
Expand Down
2 changes: 1 addition & 1 deletion tests/models/bark/test_modeling_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import inspect
import tempfile
import unittest
from functools import cached_property

from transformers import (
BarkCausalModel,
Expand All @@ -39,7 +40,6 @@
slow,
torch_device,
)
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
Expand Down
2 changes: 1 addition & 1 deletion tests/models/bart/test_modeling_bart.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import copy
import tempfile
import unittest
from functools import cached_property

import timeout_decorator # noqa

Expand All @@ -28,7 +29,6 @@
slow,
torch_device,
)
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
Expand Down
2 changes: 1 addition & 1 deletion tests/models/bart/test_tokenization_bart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import json
import os
import unittest
from functools import cached_property

from transformers import BartTokenizer, BartTokenizerFast, BatchEncoding
from transformers.models.roberta.tokenization_roberta import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, require_torch
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin, filter_roberta_detectors

Expand Down
2 changes: 1 addition & 1 deletion tests/models/beit/test_modeling_beit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Testing suite for the PyTorch BEiT model."""

import unittest
from functools import cached_property

import pytest
from datasets import load_dataset
Expand All @@ -27,7 +28,6 @@
torch_device,
)
from transformers.utils import (
cached_property,
is_torch_available,
is_vision_available,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# limitations under the License.

import unittest
from functools import cached_property

from transformers import BertGenerationTokenizer
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_torch, slow
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin

Expand Down
2 changes: 1 addition & 1 deletion tests/models/big_bird/test_tokenization_big_bird.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# limitations under the License.

import unittest
from functools import cached_property

from transformers import BigBirdTokenizer, BigBirdTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, require_torch, slow
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin

Expand Down
3 changes: 2 additions & 1 deletion tests/models/bit/test_modeling_bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
"""Testing suite for the PyTorch Bit model."""

import unittest
from functools import cached_property

from transformers import BitConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available
from transformers.utils import is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
Expand Down
2 changes: 1 addition & 1 deletion tests/models/blenderbot/test_modeling_blenderbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import tempfile
import unittest
from functools import cached_property

from transformers import BlenderbotConfig, is_torch_available
from transformers.testing_utils import (
Expand All @@ -26,7 +27,6 @@
slow,
torch_device,
)
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
Expand Down
2 changes: 1 addition & 1 deletion tests/models/blenderbot/test_tokenization_blenderbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"""Tests for Blenderbot Tokenizers, including common tests for BlenderbotSmallTokenizer."""

import unittest
from functools import cached_property

from transformers import BlenderbotTokenizer, BlenderbotTokenizerFast
from transformers.testing_utils import require_jinja
from transformers.utils import cached_property


class Blenderbot3BTokenizerTests(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import tempfile
import unittest
from functools import cached_property

from transformers import BlenderbotSmallConfig, is_torch_available
from transformers.testing_utils import (
Expand All @@ -23,7 +24,6 @@
slow,
torch_device,
)
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
Expand Down
2 changes: 1 addition & 1 deletion tests/models/bridgetower/test_modeling_bridgetower.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Testing suite for the PyTorch BridgeTower model."""

import unittest
from functools import cached_property

from transformers import (
BridgeTowerConfig,
Expand All @@ -23,7 +24,6 @@
is_vision_available,
)
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import (
Expand Down
3 changes: 2 additions & 1 deletion tests/models/byt5/test_tokenization_byt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import shutil
import tempfile
import unittest
from functools import cached_property

from transformers import AddedToken, BatchEncoding, ByT5Tokenizer
from transformers.utils import cached_property, is_tf_available, is_torch_available
from transformers.utils import is_tf_available, is_torch_available

from ...test_tokenization_common import TokenizerTesterMixin

Expand Down
2 changes: 1 addition & 1 deletion tests/models/canine/test_tokenization_canine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import shutil
import tempfile
import unittest
from functools import cached_property

from transformers import BatchEncoding, CanineTokenizer
from transformers.testing_utils import require_tokenizers, require_torch
from transformers.tokenization_utils import AddedToken
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin

Expand Down
2 changes: 1 addition & 1 deletion tests/models/codegen/test_modeling_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@


import unittest
from functools import cached_property

from transformers import CodeGenConfig, is_torch_available
from transformers.file_utils import cached_property
from transformers.testing_utils import backend_manual_seed, require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import inspect
import math
import unittest
from functools import cached_property

from transformers import ConditionalDetrConfig, ResNetConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_timm, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor
Expand Down
3 changes: 2 additions & 1 deletion tests/models/convnext/test_modeling_convnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
"""Testing suite for the PyTorch ConvNext model."""

import unittest
from functools import cached_property

from transformers import ConvNextConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available
from transformers.utils import is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
Expand Down
3 changes: 2 additions & 1 deletion tests/models/convnextv2/test_modeling_convnextv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
"""Testing suite for the PyTorch ConvNextV2 model."""

import unittest
from functools import cached_property

from transformers import ConvNextV2Config
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available
from transformers.utils import is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
Expand Down
Loading