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
04e177ad
Commit
04e177ad
authored
Aug 19, 2023
by
Casper Hansen
Browse files
Support safetensors
parent
d73d13b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
+7
-5
awq/models/auto.py
awq/models/auto.py
+2
-2
awq/models/base.py
awq/models/base.py
+5
-3
No files found.
awq/models/auto.py
View file @
04e177ad
...
...
@@ -23,11 +23,11 @@ class AutoAWQForCausalLM:
'AutoAWQForCausalLM.from_quantized or AutoAWQForCausalLM.from_pretrained'
)
@
classmethod
def
from_pretrained
(
self
,
model_path
,
trust_remote_code
=
True
)
->
BaseAWQForCausalLM
:
def
from_pretrained
(
self
,
model_path
,
trust_remote_code
=
True
,
safetensors
=
False
)
->
BaseAWQForCausalLM
:
model_type
=
check_and_get_model_type
(
model_path
,
trust_remote_code
)
return
AWQ_CAUSAL_LM_MODEL_MAP
[
model_type
].
from_pretrained
(
model_path
,
model_type
,
trust_remote_code
=
trust_remote_code
model_path
,
model_type
,
trust_remote_code
=
trust_remote_code
,
safetensors
=
safetensors
)
@
classmethod
...
...
awq/models/base.py
View file @
04e177ad
...
...
@@ -48,6 +48,7 @@ class BaseAWQForCausalLM(nn.Module):
if
run_quant
:
self
.
_awq_quant
()
self
.
is_quantized
=
True
def
_awq_quant
(
self
):
...
...
@@ -224,7 +225,7 @@ class BaseAWQForCausalLM(nn.Module):
save_dir
=
save_dir
[:
-
1
]
if
save_dir
[
-
1
]
==
'/'
else
save_dir
# Save model
if
self
.
search_result
is
None
:
if
self
.
search_result
is
None
and
not
self
.
is_quantized
:
model_name
=
f
'awq_model_w
{
self
.
quant_config
[
"w_bit"
]
}
_g
{
self
.
quant_config
[
"q_group_size"
]
}
.pt'
_save_files
(
save_dir
,
model_name
,
self
.
model
.
state_dict
())
else
:
...
...
@@ -233,7 +234,7 @@ class BaseAWQForCausalLM(nn.Module):
@
classmethod
def
from_pretrained
(
self
,
model_path
,
model_type
,
torch_dtype
:
torch
.
dtype
=
torch
.
float16
,
trust_remote_code
=
True
):
trust_remote_code
=
True
,
safetensors
=
False
):
return
self
.
from_quantized
(
model_path
,
model_type
,
...
...
@@ -241,6 +242,7 @@ class BaseAWQForCausalLM(nn.Module):
device
=
'balanced'
,
torch_dtype
=
torch_dtype
,
trust_remote_code
=
trust_remote_code
,
safetensors
=
safetensors
,
is_quantized
=
False
)
...
...
@@ -300,7 +302,7 @@ class BaseAWQForCausalLM(nn.Module):
# Load model weights
model
=
AutoModelForCausalLM
.
from_pretrained
(
model_filename
,
device_map
=
device_map
,
offload_folder
=
"offload"
,
offload_state_dict
=
True
,
torch_dtype
=
torch_dtype
model_filename
,
device_map
=
device_map
,
offload_folder
=
"offload"
,
offload_state_dict
=
True
,
torch_dtype
=
torch_dtype
,
use_safetensors
=
safetensors
)
model
.
eval
()
...
...
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