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
b53a9be2
Commit
b53a9be2
authored
Aug 22, 2023
by
Casper Hansen
Browse files
Implemented fp16 and fp32 sanitization.
parent
6708bbcb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
tinychat/stream_generators/stream_gen.py
tinychat/stream_generators/stream_gen.py
+11
-3
No files found.
tinychat/stream_generators/stream_gen.py
View file @
b53a9be2
...
@@ -30,13 +30,21 @@ def prepare_logits_processor(
...
@@ -30,13 +30,21 @@ 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
):
def
sanitize_tensor
(
tensor
:
torch
.
Tensor
):
if
tensor
.
dtype
==
torch
.
float16
:
replacement_value
=
65504
elif
tensor
.
dtype
==
torch
.
float32
:
replacement_value
=
1e20
else
:
return
tensor
# Replace positive infinity with a large finite number
# Replace positive infinity with a large finite number
tensor
[
tensor
==
float
(
'inf'
)]
=
1e20
tensor
[
tensor
==
float
(
'inf'
)]
=
replacement_value
# Replace negative infinity with a small finite number
# Replace negative infinity with a small finite number
tensor
[
tensor
==
float
(
'-inf'
)]
=
-
1e20
tensor
[
tensor
==
float
(
'-inf'
)]
=
-
replacement_value
# Replace NaNs with zero
# Replace NaNs with zero
tensor
[
torch
.
isnan
(
tensor
)]
=
0.0
tensor
[
torch
.
isnan
(
tensor
)]
=
0.0
return
tensor
return
tensor
@
torch
.
inference_mode
()
@
torch
.
inference_mode
()
...
...
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