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
OpenDAS
AutoAWQ
Commits
6708bbcb
Commit
6708bbcb
authored
Aug 22, 2023
by
Casper Hansen
Browse files
Fix #69 - sanitize NaN and infs.
parent
321d74ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
0 deletions
+9
-0
tinychat/stream_generators/stream_gen.py
tinychat/stream_generators/stream_gen.py
+9
-0
No files found.
tinychat/stream_generators/stream_gen.py
View file @
6708bbcb
...
@@ -30,6 +30,14 @@ def prepare_logits_processor(
...
@@ -30,6 +30,14 @@ def prepare_logits_processor(
processor_list
.
append
(
TopKLogitsWarper
(
top_k
))
processor_list
.
append
(
TopKLogitsWarper
(
top_k
))
return
processor_list
return
processor_list
def
sanitize_tensor
(
tensor
):
# Replace positive infinity with a large finite number
tensor
[
tensor
==
float
(
'inf'
)]
=
1e20
# Replace negative infinity with a small finite number
tensor
[
tensor
==
float
(
'-inf'
)]
=
-
1e20
# Replace NaNs with zero
tensor
[
torch
.
isnan
(
tensor
)]
=
0.0
return
tensor
@
torch
.
inference_mode
()
@
torch
.
inference_mode
()
def
StreamGenerator
(
model
,
def
StreamGenerator
(
model
,
...
@@ -82,6 +90,7 @@ def StreamGenerator(model,
...
@@ -82,6 +90,7 @@ def StreamGenerator(model,
else
:
else
:
tmp_output_ids
=
None
tmp_output_ids
=
None
last_token_logits
=
logits_processor
(
tmp_output_ids
,
logits
[:,
-
1
,
:])[
0
]
last_token_logits
=
logits_processor
(
tmp_output_ids
,
logits
[:,
-
1
,
:])[
0
]
last_token_logits
=
sanitize_tensor
(
last_token_logits
)
else
:
else
:
last_token_logits
=
logits
[
0
,
-
1
,
:]
last_token_logits
=
logits
[
0
,
-
1
,
:]
if
gen_params
.
temp
<
1e-5
or
gen_params
.
top_p
<
1e-8
:
# greedy
if
gen_params
.
temp
<
1e-5
or
gen_params
.
top_p
<
1e-8
:
# greedy
...
...
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