Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
f3feaf7f
Unverified
Commit
f3feaf7f
authored
Jan 17, 2023
by
Sayak Paul
Committed by
GitHub
Jan 17, 2023
Browse files
Change variable name to prevent shadowing (#21153)
fix: input -> input_string.
parent
cf028d0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
docs/source/en/tf_xla.mdx
docs/source/en/tf_xla.mdx
+6
-6
No files found.
docs/source/en/tf_xla.mdx
View file @
f3feaf7f
...
...
@@ -83,12 +83,12 @@ check_min_version("4.21.0")
tokenizer
=
AutoTokenizer
.
from_pretrained
(
"gpt2"
,
padding_side
=
"left"
,
pad_token
=
"</s>"
)
model
=
TFAutoModelForCausalLM
.
from_pretrained
(
"gpt2"
)
input
=
[
"TensorFlow is"
]
input
_string
=
[
"TensorFlow is"
]
#
One
line
to
create
an
XLA
generation
function
xla_generate
=
tf
.
function
(
model
.
generate
,
jit_compile
=
True
)
tokenized_input
=
tokenizer
(
input
,
return_tensors
=
"tf"
)
tokenized_input
=
tokenizer
(
input
_string
,
return_tensors
=
"tf"
)
generated_tokens
=
xla_generate
(**
tokenized_input
,
num_beams
=
2
)
decoded_text
=
tokenizer
.
decode
(
generated_tokens
[
0
],
skip_special_tokens
=
True
)
...
...
@@ -112,12 +112,12 @@ from transformers import AutoTokenizer, TFAutoModelForCausalLM
tokenizer
=
AutoTokenizer
.
from_pretrained
(
"gpt2"
,
padding_side
=
"left"
,
pad_token
=
"</s>"
)
model
=
TFAutoModelForCausalLM
.
from_pretrained
(
"gpt2"
)
input
=
[
"TensorFlow is"
]
input
_string
=
[
"TensorFlow is"
]
xla_generate
=
tf
.
function
(
model
.
generate
,
jit_compile
=
True
)
#
Here
,
we
call
the
tokenizer
with
padding
options
.
tokenized_input
=
tokenizer
(
input
,
pad_to_multiple_of
=
8
,
padding
=
True
,
return_tensors
=
"tf"
)
tokenized_input
=
tokenizer
(
input
_string
,
pad_to_multiple_of
=
8
,
padding
=
True
,
return_tensors
=
"tf"
)
generated_tokens
=
xla_generate
(**
tokenized_input
,
num_beams
=
2
)
decoded_text
=
tokenizer
.
decode
(
generated_tokens
[
0
],
skip_special_tokens
=
True
)
...
...
@@ -136,8 +136,8 @@ model = TFAutoModelForCausalLM.from_pretrained("gpt2")
xla_generate
=
tf
.
function
(
model
.
generate
,
jit_compile
=
True
)
for
input
in
[
"TensorFlow is"
,
"TensorFlow is a"
,
"TFLite is a"
]:
tokenized_input
=
tokenizer
(
input
,
pad_to_multiple_of
=
8
,
padding
=
True
,
return_tensors
=
"tf"
)
for
input
_string
in
[
"TensorFlow is"
,
"TensorFlow is a"
,
"TFLite is a"
]:
tokenized_input
=
tokenizer
(
input
_string
,
pad_to_multiple_of
=
8
,
padding
=
True
,
return_tensors
=
"tf"
)
start
=
time
.
time_ns
()
generated_tokens
=
xla_generate
(**
tokenized_input
,
num_beams
=
2
)
end
=
time
.
time_ns
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment