Skip to content

Commit 1a1f972

Browse files
CHORE Replace deprecated torch_dtype with dtype (#2837)
Note: Diffusers is left as is for now, might need an update later.
1 parent 87b90f0 commit 1a1f972

File tree

54 files changed

+209
-215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+209
-215
lines changed

docs/source/accelerate/deepspeed.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ model = AutoModelForCausalLM.from_pretrained(
263263
quantization_config=bnb_config,
264264
trust_remote_code=True,
265265
attn_implementation="flash_attention_2" if args.use_flash_attn else "eager",
266-
+ torch_dtype=quant_storage_dtype or torch.float32,
266+
+ dtype=quant_storage_dtype or torch.float32,
267267
)
268268
```
269269
270-
Notice that `torch_dtype` for `AutoModelForCausalLM` is same as the `bnb_4bit_quant_storage` data type. That's it. Everything else is handled by Trainer and TRL.
270+
Notice that `dtype` for `AutoModelForCausalLM` is same as the `bnb_4bit_quant_storage` data type. That's it. Everything else is handled by Trainer and TRL.
271271

272272
## Memory usage
273273

docs/source/accelerate/fsdp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ model = AutoModelForCausalLM.from_pretrained(
264264
quantization_config=bnb_config,
265265
trust_remote_code=True,
266266
attn_implementation="flash_attention_2" if args.use_flash_attn else "eager",
267-
+ torch_dtype=quant_storage_dtype or torch.float32,
267+
+ dtype=quant_storage_dtype or torch.float32,
268268
)
269269
```
270270

271-
Notice that `torch_dtype` for `AutoModelForCausalLM` is same as the `bnb_4bit_quant_storage` data type. That's it. Everything else is handled by Trainer and TRL.
271+
Notice that `dtype` for `AutoModelForCausalLM` is same as the `bnb_4bit_quant_storage` data type. That's it. Everything else is handled by Trainer and TRL.
272272

273273
## Memory usage
274274

docs/source/developer_guides/lora.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ from peft import PeftModel
539539
import torch
540540

541541
base_model = AutoModelForCausalLM.from_pretrained(
542-
"mistralai/Mistral-7B-v0.1", torch_dtype=torch.float16, device_map="auto"
542+
"mistralai/Mistral-7B-v0.1", dtype=torch.float16, device_map="auto"
543543
)
544544
```
545545

@@ -813,7 +813,7 @@ To encode general knowledge, GenKnowSub subtracts the average of the provided ge
813813
> # Loading the model
814814
> base_model = AutoModelForCausalLM.from_pretrained(
815815
> "microsoft/Phi-3-mini-4k-instruct",
816-
> torch_dtype=torch.bfloat16,
816+
> dtype=torch.bfloat16,
817817
> device_map="auto",
818818
> quantization_config=bnb_config,
819819
> )

docs/source/developer_guides/quantization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ The models support LoRA adapter tuning. To tune the quantized model you'll need
144144
```py
145145
quantized_model = AutoModelForCausalLM.from_pretrained(
146146
"BlackSamorez/Mixtral-8x7b-AQLM-2Bit-1x16-hf-test-dispatch",
147-
torch_dtype="auto", device_map="auto", low_cpu_mem_usage=True,
147+
dtype="auto", device_map="auto", low_cpu_mem_usage=True,
148148
)
149149

150150
peft_config = LoraConfig(...)

docs/source/developer_guides/troubleshooting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ python -m pip install git+https://github.com/huggingface/peft
4343

4444
### ValueError: Attempting to unscale FP16 gradients
4545

46-
This error probably occurred because the model was loaded with `torch_dtype=torch.float16` and then used in an automatic mixed precision (AMP) context, e.g. by setting `fp16=True` in the [`~transformers.Trainer`] class from 🤗 Transformers. The reason is that when using AMP, trainable weights should never use fp16. To make this work without loading the whole model in fp32, add the following to your code:
46+
This error probably occurred because the model was loaded with `dtype=torch.float16` and then used in an automatic mixed precision (AMP) context, e.g. by setting `fp16=True` in the [`~transformers.Trainer`] class from 🤗 Transformers. The reason is that when using AMP, trainable weights should never use fp16. To make this work without loading the whole model in fp32, add the following to your code:
4747

4848
```python
4949
peft_model = get_peft_model(...)
@@ -294,7 +294,7 @@ It is possible to get this information for non-PEFT models if they are using PEF
294294

295295
>>> path = "runwayml/stable-diffusion-v1-5"
296296
>>> lora_id = "takuma104/lora-test-text-encoder-lora-target"
297-
>>> pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
297+
>>> pipe = StableDiffusionPipeline.from_pretrained(path, dtype=torch.float16)
298298
>>> pipe.load_lora_weights(lora_id, adapter_name="adapter-1")
299299
>>> pipe.load_lora_weights(lora_id, adapter_name="adapter-2")
300300
>>> pipe.set_lora_device(["adapter-2"], "cuda")

examples/arrow_multitask/arrow_phi3_mini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def evaluate_on_multi_choice_batched(
303303
# Loading the model
304304
base_model = AutoModelForCausalLM.from_pretrained(
305305
MODEL_NAME,
306-
torch_dtype=torch.bfloat16,
306+
dtype=torch.bfloat16,
307307
device_map="auto",
308308
quantization_config=bnb_config,
309309
)

examples/boft_controlnet/test_controlnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def main(args):
8484
args.pretrained_model_name_or_path,
8585
controlnet=controlnet,
8686
unet=unet.model,
87-
torch_dtype=torch.float32,
87+
dtype=torch.float32,
8888
requires_safety_checker=False,
8989
).to(device)
9090

examples/boft_dreambooth/train_dreambooth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ def main(args):
139139
cur_class_images = len(list(class_images_dir.iterdir()))
140140

141141
if cur_class_images < args.num_class_images:
142-
torch_dtype = torch.float16 if accelerator.device.type in ["cuda", "xpu"] else torch.float32
142+
dtype = torch.float16 if accelerator.device.type in ["cuda", "xpu"] else torch.float32
143143
if args.prior_generation_precision == "fp32":
144-
torch_dtype = torch.float32
144+
dtype = torch.float32
145145
elif args.prior_generation_precision == "fp16":
146-
torch_dtype = torch.float16
146+
dtype = torch.float16
147147
elif args.prior_generation_precision == "bf16":
148-
torch_dtype = torch.bfloat16
148+
dtype = torch.bfloat16
149149
pipeline = DiffusionPipeline.from_pretrained(
150150
args.pretrained_model_name_or_path,
151-
torch_dtype=torch_dtype,
151+
dtype=dtype,
152152
safety_checker=None,
153153
revision=args.revision,
154154
)

examples/bone_finetuning/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
1111
from trl import SFTConfig, SFTTrainer
1212
from datasets import load_dataset
1313

14-
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf", torch_dtype=torch.bfloat16, device_map="auto")
14+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf", dtype=torch.bfloat16, device_map="auto")
1515
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
1616
tokenizer.pad_token_id = tokenizer.eos_token_id
1717
bone_config = BoneConfig(
@@ -47,7 +47,7 @@ from peft import PeftModel
4747
from transformers import AutoModelForCausalLM
4848

4949
model = AutoModelForCausalLM.from_pretrained(
50-
"meta-llama/Llama-2-7b-hf", torch_dtype=torch.bfloat16, device_map="auto"
50+
"meta-llama/Llama-2-7b-hf", dtype=torch.bfloat16, device_map="auto"
5151
)
5252
peft_model = PeftModel.from_pretrained(model, "bone-llama-2-7b")
5353
```

examples/bone_finetuning/bone_finetuning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ScriptArguments(SFTConfig):
5757
print(f"No available pre-processed model, manually initialize a Bone using {script_args.base_model_name_or_path}.")
5858
model = AutoModelForCausalLM.from_pretrained(
5959
script_args.base_model_name_or_path,
60-
torch_dtype=(
60+
dtype=(
6161
torch.float16
6262
if script_args.bits == "fp16"
6363
else (torch.bfloat16 if script_args.bits == "bf16" else torch.float32)

0 commit comments

Comments
 (0)