Open i7p9h9 opened 1 year ago
use accelerate, accelerator.prepare(model)
@SKDDJ Even when using huggingfaces accelerator I am struggeling to make it work for the multi-gpu setting (works with only 1 gpu). It leads to a pytorch warning message
an autograd kernel was not registered to the Autograd key(s) but we are trying to backprop through it.
Furthermore it breaks when tracking the gradients using wandb.watch() since the grad.data object send to wandb is None indicating that the gradients dont get backpropagated properly.
Im currently using pytorch 2.2.0, can you maybe reference what version you tried?
@niklasbubeck Hi, my torch version is "torch 2.2.2", maybe you can try the latest torch to see if this works:)
@niklasbubeck Note that you'd better do this once you've load your model
# Load pretrained model and tokenizer
config = AutoConfig.from_pretrained(
model_args.config_name if model_args.config_name else model_args.model_name_or_path,
num_labels=num_labels,
finetuning_task=data_args.task_name,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
# use_auth_token=True if model_args.use_auth_token else None,
)
tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
cache_dir=model_args.cache_dir,
use_fast=model_args.use_fast_tokenizer,
revision=model_args.model_revision,
# use_auth_token=True if model_args.use_auth_token else None,
)
model = AutoModelForSequenceClassification.from_pretrained(
model_args.model_name_or_path,
from_tf=bool(".ckpt" in model_args.model_name_or_path),
config=config,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
# use_auth_token=True if model_args.use_auth_token else None,
ignore_mismatched_sizes=model_args.ignore_mismatched_sizes,
)
model, tokenizer = accelerator.prepare(model, tokenizer)
# ... your other code
apply_lora(model) # add lora here after use prepare(model)
hope this help you.
Minimum example