Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
619ecfe2
Unverified
Commit
619ecfe2
authored
Jan 18, 2024
by
Sanchit Gandhi
Committed by
GitHub
Jan 18, 2024
Browse files
[Whisper Tok] Move token ids to CPU when computing offsets (#28485)
* move token ids to cpu * check for torch attr
parent
0eaa5ea3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
0 deletions
+6
-0
src/transformers/models/whisper/tokenization_whisper.py
src/transformers/models/whisper/tokenization_whisper.py
+3
-0
src/transformers/models/whisper/tokenization_whisper_fast.py
src/transformers/models/whisper/tokenization_whisper_fast.py
+3
-0
No files found.
src/transformers/models/whisper/tokenization_whisper.py
View file @
619ecfe2
...
@@ -553,6 +553,9 @@ class WhisperTokenizer(PreTrainedTokenizer):
...
@@ -553,6 +553,9 @@ class WhisperTokenizer(PreTrainedTokenizer):
The time ratio to convert from token to time.
The time ratio to convert from token to time.
"""
"""
offsets
=
[]
offsets
=
[]
# ensure torch tensor of token ids is placed on cpu
if
"torch"
in
str
(
type
(
token_ids
))
and
(
hasattr
(
token_ids
,
"cpu"
)
and
callable
(
token_ids
.
cpu
)):
token_ids
=
token_ids
.
cpu
()
token_ids
=
np
.
array
(
token_ids
)
token_ids
=
np
.
array
(
token_ids
)
if
token_ids
.
shape
[
0
]
>
1
and
len
(
token_ids
.
shape
)
>
1
:
if
token_ids
.
shape
[
0
]
>
1
and
len
(
token_ids
.
shape
)
>
1
:
raise
ValueError
(
"Can only process a single input at a time"
)
raise
ValueError
(
"Can only process a single input at a time"
)
...
...
src/transformers/models/whisper/tokenization_whisper_fast.py
View file @
619ecfe2
...
@@ -248,6 +248,9 @@ class WhisperTokenizerFast(PreTrainedTokenizerFast):
...
@@ -248,6 +248,9 @@ class WhisperTokenizerFast(PreTrainedTokenizerFast):
The time ratio to convert from token to time.
The time ratio to convert from token to time.
"""
"""
offsets
=
[]
offsets
=
[]
# ensure torch tensor of token ids is placed on cpu
if
"torch"
in
str
(
type
(
token_ids
))
and
(
hasattr
(
token_ids
,
"cpu"
)
and
callable
(
token_ids
.
cpu
)):
token_ids
=
token_ids
.
cpu
()
token_ids
=
np
.
array
(
token_ids
)
token_ids
=
np
.
array
(
token_ids
)
if
token_ids
.
shape
[
0
]
>
1
and
len
(
token_ids
.
shape
)
>
1
:
if
token_ids
.
shape
[
0
]
>
1
and
len
(
token_ids
.
shape
)
>
1
:
raise
ValueError
(
"Can only process a single input at a time"
)
raise
ValueError
(
"Can only process a single input at a time"
)
...
...
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