Skip to content

Commit

Permalink
fix dtype when init HF model from config (#11420)
Browse files Browse the repository at this point in the history
* fix dtype when init HF model from config

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* Apply isort and black reformatting

Signed-off-by: akoumpa <[email protected]>

---------

Signed-off-by: Alexandros Koumparoulis <[email protected]>
Signed-off-by: akoumpa <[email protected]>
Co-authored-by: akoumpa <[email protected]>
  • Loading branch information
akoumpa and akoumpa authored Nov 28, 2024
1 parent 18fe970 commit 09e9bbc
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(
model_transform=None,
model_accelerator=None,
trust_remote_code=False,
default_dtype=torch.bfloat16,
):
super().__init__()
self.save_hyperparameters()
Expand All @@ -53,6 +54,7 @@ def __init__(
self.model_transform = model_transform
self.model_accelerator = model_accelerator
self.trust_remote_code = trust_remote_code
self.default_dtype = default_dtype

@property
def tokenizer(self):
Expand All @@ -79,7 +81,10 @@ def configure_model(self):
from transformers import AutoConfig

config = AutoConfig.from_pretrained(self.model_name, trust_remote_code=self.trust_remote_code)
self.model = AutoModelForCausalLM.from_config(config, trust_remote_code=self.trust_remote_code)
dtype = getattr(config, 'torch_dtype', self.default_dtype)
self.model = AutoModelForCausalLM.from_config(
config, torch_dtype=dtype, trust_remote_code=self.trust_remote_code
)

if self.model_accelerator is not None:
self.model_accelerator(self.model)
Expand Down

0 comments on commit 09e9bbc

Please sign in to comment.