/
usr
/
local
/
lib
/
python3.6
/
site-packages
/
transformers
/
/usr/local/lib/python3.6/site-packages/transformers
mkdir
upload
Name
Size
Mode
Actions
benchmark/
-
0755
rm
commands/
-
0755
rm
data/
-
0755
rm
models/
-
0755
rm
onnx/
-
0755
rm
pipelines/
-
0755
rm
sagemaker/
-
0755
rm
utils/
-
0755
rm
__pycache__/
-
0755
rm
activations.py
6612
0644
edit
dl
rm
activations_tf.py
4268
0644
edit
dl
rm
configuration_utils.py
46765
0644
edit
dl
rm
convert_graph_to_onnx.py
19575
0644
edit
dl
rm
convert_pytorch_checkpoint_to_tf2.py
16640
0644
edit
dl
rm
convert_slow_tokenizer.py
37626
0644
edit
dl
rm
convert_slow_tokenizers_checkpoints_to_fast.py
4954
0644
edit
dl
rm
convert_tf_hub_seq_to_seq_bert_to_pytorch.py
2899
0644
edit
dl
rm
debug_utils.py
12887
0644
edit
dl
rm
deepspeed.py
18883
0644
edit
dl
rm
dependency_versions_check.py
1767
0644
edit
dl
rm
dependency_versions_table.py
2390
0644
edit
dl
rm
dynamic_module_utils.py
19306
0644
edit
dl
rm
feature_extraction_sequence_utils.py
18074
0644
edit
dl
rm
feature_extraction_utils.py
26768
0644
edit
dl
rm
file_utils.py
3930
0644
edit
dl
rm
generation_beam_constraints.py
19078
0644
edit
dl
rm
generation_beam_search.py
40145
0644
edit
dl
rm
generation_flax_logits_process.py
10879
0644
edit
dl
rm
generation_flax_utils.py
38708
0644
edit
dl
rm
generation_logits_process.py
30336
0644
edit
dl
rm
generation_stopping_criteria.py
5509
0644
edit
dl
rm
generation_tf_logits_process.py
17503
0644
edit
dl
rm
generation_tf_utils.py
130671
0644
edit
dl
rm
generation_utils.py
177118
0644
edit
dl
rm
hf_argparser.py
11901
0644
edit
dl
rm
image_utils.py
12860
0644
edit
dl
rm
integrations.py
40203
0644
edit
dl
rm
keras_callbacks.py
18902
0644
edit
dl
rm
modelcard.py
35278
0644
edit
dl
rm
modeling_flax_outputs.py
35514
0644
edit
dl
rm
modeling_flax_pytorch_utils.py
12296
0644
edit
dl
rm
modeling_flax_utils.py
37661
0644
edit
dl
rm
modeling_outputs.py
60327
0644
edit
dl
rm
modeling_tf_outputs.py
46107
0644
edit
dl
rm
modeling_tf_pytorch_utils.py
19916
0644
edit
dl
rm
modeling_tf_utils.py
100832
0644
edit
dl
rm
modeling_utils.py
137800
0644
edit
dl
rm
optimization.py
27756
0644
edit
dl
rm
optimization_tf.py
15722
0644
edit
dl
rm
processing_utils.py
10559
0644
edit
dl
rm
py.typed
1
0644
edit
dl
rm
pytorch_utils.py
1649
0644
edit
dl
rm
testing_utils.py
48292
0644
edit
dl
rm
tf_utils.py
1568
0644
edit
dl
rm
tokenization_utils.py
39867
0644
edit
dl
rm
tokenization_utils_base.py
170159
0644
edit
dl
rm
tokenization_utils_fast.py
32909
0644
edit
dl
rm
trainer.py
143103
0644
edit
dl
rm
trainer_callback.py
23199
0644
edit
dl
rm
trainer_pt_utils.py
44764
0644
edit
dl
rm
trainer_seq2seq.py
10396
0644
edit
dl
rm
trainer_tf.py
34564
0644
edit
dl
rm
trainer_utils.py
18509
0644
edit
dl
rm
training_args.py
68042
0644
edit
dl
rm
training_args_seq2seq.py
2829
0644
edit
dl
rm
training_args_tf.py
14267
0644
edit
dl
rm
__init__.py
171952
0644
edit
dl
rm
Edit:
/usr/local/lib/python3.6/site-packages/transformers/activations_tf.py
(4268B)
# Copyright 2020 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. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import math import tensorflow as tf from packaging import version def _gelu(x): """ Gaussian Error Linear Unit. Original Implementation of the gelu activation function in Google Bert repo when initially created. For information: OpenAI GPT's gelu is slightly different (and gives slightly different results): 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) Also see https://arxiv.org/abs/1606.08415 """ x = tf.convert_to_tensor(x) cdf = 0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0), x.dtype))) return x * cdf def _gelu_new(x): """ Gaussian Error Linear Unit. This is a smoother version of the GELU. Original paper: https://arxiv.org/abs/1606.0841 Args: x: float Tensor to perform activation Returns: `x` with the GELU activation applied. """ x = tf.convert_to_tensor(x) pi = tf.cast(math.pi, x.dtype) coeff = tf.cast(0.044715, x.dtype) cdf = 0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi) * (x + coeff * tf.pow(x, 3)))) return x * cdf def mish(x): x = tf.convert_to_tensor(x) return x * tf.tanh(tf.math.softplus(x)) def gelu_fast(x): x = tf.convert_to_tensor(x) coeff1 = tf.cast(0.044715, x.dtype) coeff2 = tf.cast(0.7978845608, x.dtype) return 0.5 * x * (1.0 + tf.tanh(x * coeff2 * (1.0 + coeff1 * x * x))) def quick_gelu(x): x = tf.convert_to_tensor(x) coeff = tf.cast(1.702, x.dtype) return x * tf.math.sigmoid(coeff * x) def gelu_10(x): """ Clip the range of possible GeLU outputs between [-10, 10]. This is especially useful for quantization purpose, as it allows mapping 2 negatives values in the GeLU spectrum. For more information on this trick, please refer to https://arxiv.org/abs/2004.09602 Gaussian Error Linear Unit. Original Implementation of the gelu activation function in Google Bert repo when initially created. For information: OpenAI GPT's gelu is slightly different (and gives slightly different results): 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) Also see https://arxiv.org/abs/1606.08415 :param x: :return: """ return tf.clip_by_value(_gelu(x), -10, 10) def glu(x, axis=-1): """ Gated Linear Unit. Implementation as defined in the original paper (see https://arxiv.org/abs/1612.08083), where the input `x` is split in two halves across a dimension (`axis`), A and B, returning A * sigmoid(B). Args: `x`: float Tensor to perform activation `axis`: dimension across which `x` be split in half Returns: `x` with the GLU activation applied (with its size halved across the dimension `axis`). """ a, b = tf.split(x, 2, axis=axis) return a * tf.math.sigmoid(b) if version.parse(tf.version.VERSION) >= version.parse("2.4"): def approximate_gelu_wrap(x): return tf.keras.activations.gelu(x, approximate=True) gelu = tf.keras.activations.gelu gelu_new = approximate_gelu_wrap else: gelu = _gelu gelu_new = _gelu_new ACT2FN = { "gelu": gelu, "relu": tf.keras.activations.relu, "swish": tf.keras.activations.swish, "silu": tf.keras.activations.swish, "gelu_new": gelu_new, "mish": mish, "tanh": tf.keras.activations.tanh, "gelu_fast": gelu_fast, "quick_gelu": quick_gelu, "gelu_10": gelu_10, "glu": glu, } def get_tf_activation(activation_string): if activation_string in ACT2FN: return ACT2FN[activation_string] else: raise KeyError(f"function {activation_string} not found in ACT2FN mapping {list(ACT2FN.keys())}")
Save
cmd:
run