Skip to content

Commit 0c66232

Browse files
committed
more
1 parent 928d441 commit 0c66232

16 files changed

+22
-249
lines changed

docker/consistency.dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ RUN apt-get update && apt-get install -y time git g++ pkg-config make git-lfs
66
ENV UV_PYTHON=/usr/local/bin/python
77
RUN pip install uv && uv pip install --no-cache-dir -U pip setuptools GitPython
88
RUN uv pip install --no-cache-dir --upgrade 'torch' 'torchaudio' 'torchvision' --index-url https://download.pytorch.org/whl/cpu
9-
# tensorflow pin matching setup.py
109
RUN uv pip install --no-cache-dir pypi-kenlm
11-
RUN uv pip install --no-cache-dir "tensorflow-cpu<2.16" "tf-keras<2.16"
12-
RUN uv pip install --no-cache-dir "git+https://github.com/huggingface/transformers.git@${REF}#egg=transformers[flax,quality,testing,torch-speech,vision]"
10+
RUN uv pip install --no-cache-dir "git+https://github.com/huggingface/transformers.git@${REF}#egg=transformers[quality,testing,torch-speech,vision]"
1311
RUN git lfs install
1412

1513
RUN uv pip uninstall transformers

docs/source/ar/_toctree.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@
123123
title: تشغيل التدريب على Amazon SageMaker
124124
- local: serialization
125125
title: التصدير إلى ONNX
126-
- local: tflite
127-
title: التصدير إلى TFLite
128126
- local: torchscript
129127
title: التصدير إلى TorchScript
130128
- local: notebooks
@@ -184,8 +182,6 @@
184182
# title: التدريب الفعال على وحدة المعالجة المركزية (CPU)
185183
# - local: perf_train_cpu_many
186184
# title: التدريب الموزع لوحدة المعالجة المركزية (CPU)
187-
# - local: perf_train_tpu_tf
188-
# title: التدريب على (TPU) باستخدام TensorFlow
189185
# - local: perf_train_special
190186
# title: تدريب PyTorch على Apple silicon
191187
# - local: perf_hardware
@@ -203,8 +199,6 @@
203199
# title: إنشاء نموذج كبير
204200
# - local: debugging
205201
# title: تصحيح الأخطاء البرمجية
206-
# - local: tf_xla
207-
# title: تكامل XLA لنماذج TensorFlow
208202
# - local: perf_torch_compile
209203
# title: تحسين الاستدلال باستخدام `torch.compile()`
210204
# title: الأداء وقابلية التوسع

docs/source/en/_toctree.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@
218218
sections:
219219
- local: serialization
220220
title: ONNX
221-
- local: tflite
222-
title: LiteRT
223221
- local: executorch
224222
title: ExecuTorch
225223
- local: torchscript

docs/source/hi/_toctree.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22
- local: pipeline_tutorial
33
title: पाइपलाइनों के साथ अनुमान चलाएँ
44
- local: accelerate
5-
title: 🤗 Accelerate के साथ वितरित प्रशिक्षण सेट करें
6-
- local: tflite
7-
title: TFLite में निर्यात करें
5+
title: 🤗 Accelerate के साथ वितरित प्रशिक्षण सेट करें

docs/source/ja/_toctree.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@
109109
title: チャットモデルのテンプレート
110110
- local: serialization
111111
title: ONNX へのエクスポート
112-
- local: tflite
113-
title: TFLite へのエクスポート
114112
- local: torchscript
115113
title: トーチスクリプトへのエクスポート
116114
- local: community
@@ -132,8 +130,6 @@
132130
title: 分散CPUトレーニング
133131
- local: perf_train_tpu
134132
title: TPU に関するトレーニング
135-
- local: perf_train_tpu_tf
136-
title: TensorFlow を使用した TPU のトレーニング
137133
- local: perf_train_special
138134
title: 特殊なハードウェアに関するトレーニング
139135
- local: perf_hardware
@@ -153,8 +149,6 @@
153149
title: 推論の最適化
154150
- local: big_models
155151
title: 大きなモデルのインスタンス化
156-
- local: tf_xla
157-
title: TensorFlowモデルのXLA統合
158152
- local: perf_torch_compile
159153
title: torch.compile()を使用した推論の最適化
160154
title: パフォーマンスとスケーラビリティ

docs/source/ko/_toctree.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@
208208
sections:
209209
- local: serialization
210210
title: ONNX로 내보내기
211-
- local: tflite
212-
title: TFLite로 내보내기
213211
- local: executorch
214212
title: ExecuTorch
215213
- local: torchscript

docs/source/ms/_toctree.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@
115115
title: Latihan pada banyak CPU
116116
- local: perf_train_tpu
117117
title: Latihan mengenai TPU
118-
- local: perf_train_tpu_tf
119-
title: Latihan tentang TPU dengan TensorFlow
120118
- local: perf_train_special
121119
title: Latihan mengenai Perkakasan Khusus
122120
- local: perf_infer_cpu
@@ -135,8 +133,6 @@
135133
title: Penyahpepijatan
136134
- local: hpo_train
137135
title: Carian Hiperparameter menggunakan API Pelatih
138-
- local: tf_xla
139-
title: Penyepaduan XLA untuk Model TensorFlow
140136
title: Prestasi dan kebolehskalaan
141137
- sections:
142138
- local: contributing

docs/source/zh/_toctree.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
title: 聊天模型的模板
4545
- local: serialization
4646
title: 导出为 ONNX
47-
- local: tflite
48-
title: 导出为 TFLite
4947
- local: torchscript
5048
title: 导出为 TorchScript
5149
- local: gguf
@@ -76,8 +74,6 @@
7674
title: 实例化大模型
7775
- local: debugging
7876
title: 问题定位及解决
79-
- local: tf_xla
80-
title: TensorFlow模型的XLA集成
8177
- local: perf_torch_compile
8278
title: 使用 `torch.compile()` 优化推理
8379
title: 性能和可扩展性

examples/modular-transformers/image_processing_new_imgproc_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def preprocess(
152152
images: ImageInput,
153153
do_resize: Optional[bool] = None,
154154
size: Optional[dict[str, int]] = None,
155-
resample: PILImageResampling = None,
155+
resample: Optional[PILImageResampling] = None,
156156
do_rescale: Optional[bool] = None,
157157
rescale_factor: Optional[float] = None,
158158
do_normalize: Optional[bool] = None,
@@ -221,6 +221,7 @@ def preprocess(
221221

222222
size = size if size is not None else self.size
223223
size = get_size_dict(size, default_to_square=False)
224+
images = self.fetch_images(images)
224225
images = make_flat_list_of_images(images)
225226

226227
if not valid_images(images):

examples/modular-transformers/modeling_dummy_bert.py

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
# modular_dummy_bert.py file directly. One of our CI enforces this.
66
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
77
import math
8-
import os
98
from typing import Optional, Union
109

1110
import torch
12-
from packaging import version
1311
from torch import nn
1412

1513
from ...activations import ACT2FN
@@ -19,7 +17,7 @@
1917
from ...modeling_outputs import BaseModelOutputWithPastAndCrossAttentions, BaseModelOutputWithPoolingAndCrossAttentions
2018
from ...modeling_utils import PreTrainedModel
2119
from ...pytorch_utils import apply_chunking_to_forward, find_pruneable_heads_and_indices, prune_linear_layer
22-
from ...utils import auto_docstring, get_torch_version, logging
20+
from ...utils import auto_docstring, logging
2321
from ...utils.deprecation import deprecate_kwarg
2422
from .configuration_dummy_bert import DummyBertConfig
2523

@@ -36,8 +34,7 @@ def __init__(self, config):
3634
self.position_embeddings = nn.Embedding(config.max_position_embeddings, config.hidden_size)
3735
self.token_type_embeddings = nn.Embedding(config.type_vocab_size, config.hidden_size)
3836

39-
# self.LayerNorm is not snake-cased to stick with TensorFlow model variable name and be able to load
40-
# any TensorFlow checkpoint file
37+
# self.LayerNorm is not snake-cased due to old tensorflow checkpoint name matching
4138
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
4239
self.dropout = nn.Dropout(config.hidden_dropout_prob)
4340
# position_ids (1, len position emb) is contiguous in memory and exported when serialized
@@ -228,7 +225,6 @@ class DummyBertSdpaSelfAttention(DummyBertSelfAttention):
228225
def __init__(self, config, position_embedding_type=None, layer_idx=None):
229226
super().__init__(config, position_embedding_type=position_embedding_type, layer_idx=layer_idx)
230227
self.dropout_prob = config.attention_probs_dropout_prob
231-
self.require_contiguous_qkv = version.parse(get_torch_version()) < version.parse("2.2.0")
232228

233229
# Adapted from DummyBertSelfAttention
234230
@deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
@@ -308,14 +304,6 @@ def forward(
308304
if is_cross_attention and isinstance(past_key_values, EncoderDecoderCache):
309305
past_key_values.is_updated[self.layer_idx] = True
310306

311-
# SDPA with memory-efficient backend is broken in torch==2.1.2 when using non-contiguous inputs and a custom
312-
# attn_mask, so we need to call `.contiguous()` here. This was fixed in torch==2.2.0.
313-
# Reference: https://github.com/pytorch/pytorch/issues/112577
314-
if self.require_contiguous_qkv and query_layer.device.type == "cuda" and attention_mask is not None:
315-
query_layer = query_layer.contiguous()
316-
key_layer = key_layer.contiguous()
317-
value_layer = value_layer.contiguous()
318-
319307
# We dispatch to SDPA's Flash Attention or Efficient kernels via this `is_causal` if statement instead of an inline conditional assignment
320308
# in SDPA to support both torch.compile's dynamic shapes and full graph options. An inline conditional prevents dynamic shapes from compiling.
321309
# The tgt_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create
@@ -655,92 +643,16 @@ def forward(self, hidden_states):
655643
return hidden_states
656644

657645

658-
def load_tf_weights_in_dummy_bert(model, config, tf_checkpoint_path):
659-
"""Load tf checkpoints in a pytorch model."""
660-
try:
661-
import re
662-
663-
import numpy as np
664-
import tensorflow as tf
665-
except ImportError:
666-
logger.error(
667-
"Loading a TensorFlow model in PyTorch, requires TensorFlow to be installed. Please see "
668-
"https://www.tensorflow.org/install/ for installation instructions."
669-
)
670-
raise
671-
tf_path = os.path.abspath(tf_checkpoint_path)
672-
logger.info(f"Converting TensorFlow checkpoint from {tf_path}")
673-
# Load weights from TF model
674-
init_vars = tf.train.list_variables(tf_path)
675-
names = []
676-
arrays = []
677-
for name, shape in init_vars:
678-
logger.info(f"Loading TF weight {name} with shape {shape}")
679-
array = tf.train.load_variable(tf_path, name)
680-
names.append(name)
681-
arrays.append(array)
682-
683-
for name, array in zip(names, arrays):
684-
name = name.split("/")
685-
# adam_v and adam_m are variables used in AdamWeightDecayOptimizer to calculated m and v
686-
# which are not required for using pretrained model
687-
if any(
688-
n in ["adam_v", "adam_m", "AdamWeightDecayOptimizer", "AdamWeightDecayOptimizer_1", "global_step"]
689-
for n in name
690-
):
691-
logger.info(f"Skipping {'/'.join(name)}")
692-
continue
693-
pointer = model
694-
for m_name in name:
695-
if re.fullmatch(r"[A-Za-z]+_\d+", m_name):
696-
scope_names = re.split(r"_(\d+)", m_name)
697-
else:
698-
scope_names = [m_name]
699-
if scope_names[0] == "kernel" or scope_names[0] == "gamma":
700-
pointer = getattr(pointer, "weight")
701-
elif scope_names[0] == "output_bias" or scope_names[0] == "beta":
702-
pointer = getattr(pointer, "bias")
703-
elif scope_names[0] == "output_weights":
704-
pointer = getattr(pointer, "weight")
705-
elif scope_names[0] == "squad":
706-
pointer = getattr(pointer, "classifier")
707-
else:
708-
try:
709-
pointer = getattr(pointer, scope_names[0])
710-
except AttributeError:
711-
logger.info(f"Skipping {'/'.join(name)}")
712-
continue
713-
if len(scope_names) >= 2:
714-
num = int(scope_names[1])
715-
pointer = pointer[num]
716-
if m_name[-11:] == "_embeddings":
717-
pointer = getattr(pointer, "weight")
718-
elif m_name == "kernel":
719-
array = np.transpose(array)
720-
try:
721-
if pointer.shape != array.shape:
722-
raise ValueError(f"Pointer shape {pointer.shape} and array shape {array.shape} mismatched")
723-
except ValueError as e:
724-
e.args += (pointer.shape, array.shape)
725-
raise
726-
logger.info(f"Initialize PyTorch weight {name}")
727-
pointer.data = torch.from_numpy(array)
728-
return model
729-
730-
731646
@auto_docstring
732647
class DummyBertPreTrainedModel(PreTrainedModel):
733648
config: DummyBertConfig
734-
load_tf_weights = load_tf_weights_in_dummy_bert
735649
base_model_prefix = "dummy_bert"
736650
supports_gradient_checkpointing = True
737651
_supports_sdpa = True
738652

739653
def _init_weights(self, module):
740654
"""Initialize the weights"""
741655
if isinstance(module, nn.Linear):
742-
# Slightly different from the TF version which uses truncated_normal for initialization
743-
# cf https://github.com/pytorch/pytorch/pull/5617
744656
module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
745657
if module.bias is not None:
746658
module.bias.data.zero_()

0 commit comments

Comments
 (0)