Open 25Varun opened 8 months ago
I am also facing the same issue, pytorch_model.bin is not being saved. Please help
I have also met this problem, and there is a possible solution: make sure warmup steps is lower than your num_epochs number. It is worked in my model, since I changed the warmup steps, there have been no more same problems :)
Sorry, I got the same issue. I followed your advice, changed the warmup steps lower than num_epochs, but it's not fixing this issue. Please help me.
While fine tuning vasita/whisper-kannada-small model on customized dataset, after training, in the output directory, all the other json and bin files are getting saved except pytorch_model.bin file and after saving it says some keys were missing while saving the model [proj_out.weight]. Why is that I have no clue, I actually run the whole thing on google colab.
import torch import evaluate from dataclasses import dataclass from typing import Any, Dict, List, Union from datasets import DatasetDict, Audio, load_from_disk, concatenate_datasets from transformers.models.whisper.english_normalizer import BasicTextNormalizer from transformers import ( WhisperFeatureExtractor, WhisperTokenizer, WhisperProcessor, WhisperForConditionalGeneration, Seq2SeqTrainingArguments, Seq2SeqTrainer, )
model_name = 'vasista22/whisper-kannada-small' language = 'Kannada' sampling_rate = 16000 num_proc = 1 train_strategy = 'steps' learning_rate = 1.75e-5*0.1 warmup = 20 train_batchsize = 16 eval_batchsize = 8
num_epochs = 20
num_steps = 50 resume_from_ckpt = None output_dir = 'model_1' train_datasets = ['/content/drive/MyDrive/Children/prepared_data'] eval_datasets = ['/content/drive/MyDrive/Children/prepared_data']
gradient_checkpointing = True freeze_feature_encoder = False freeze_encoder = False do_normalize_eval = True do_lower_case = False do_remove_punctuation = False normalizer = BasicTextNormalizer()
feature_extractor = WhisperFeatureExtractor.from_pretrained(model_name) tokenizer = WhisperTokenizer.from_pretrained(model_name, language=language, task="transcribe") processor = WhisperProcessor.from_pretrained(model_name, language=language, task="transcribe") model = WhisperForConditionalGeneration.from_pretrained(model_name)
if model.config.decoder_start_token_id is None: raise ValueError("Make sure that
config.decoder_start_token_id
is correctly defined")if freeze_feature_encoder: model.freeze_feature_encoder()
if freeze_encoder: model.freeze_encoder() model.model.encoder.gradient_checkpointing = False
model.config.forced_decoder_ids = None model.config.suppress_tokens = []
if gradient_checkpointing: model.config.use_cache = False
def load_custom_dataset(split): ds = [] if split == 'train': for dset in train_datasets: ds.append(load_from_disk(dset)) if split == 'eval': for dset in eval_datasets: ds.append(load_from_disk(dset))
def prepare_dataset(batch):
load and (possibly) resample audio data to 16kHz
max_label_length = model.config.max_length min_input_length = 0.0 max_input_length = 30.0 def is_in_length_range(length, labels): return min_input_length < length < max_input_length and 0 < len(labels) < max_label_length
print('DATASET PREPARATION IN PROGRESS...') raw_dataset = DatasetDict() raw_dataset["train"] = load_custom_dataset('train') raw_dataset["eval"] = load_custom_dataset('eval')
raw_dataset = raw_dataset.cast_column("audio", Audio(sampling_rate=sampling_rate)) raw_dataset = raw_dataset.map(prepare_dataset, num_proc=num_proc)
raw_dataset = raw_dataset.filter( is_in_length_range, input_columns=["input_length", "labels"], num_proc=num_proc, )
@dataclass class DataCollatorSpeechSeq2SeqWithPadding: processor: Any
data_collator = DataCollatorSpeechSeq2SeqWithPadding(processor=processor) print('DATASET PREPARATION COMPLETED')
metric = evaluate.load("wer") def compute_metrics(pred): pred_ids = pred.predictions label_ids = pred.label_ids
############################### TRAINING ARGS AND TRAINING ############################
if train_strategy == 'epoch': training_args = Seq2SeqTrainingArguments( output_dir=output_dir, per_device_train_batch_size=train_batchsize, gradient_accumulation_steps=1, learning_rate=learning_rate, warmup_steps=warmup, gradient_checkpointing=gradient_checkpointing, fp16=True, evaluation_strategy="epoch", save_strategy="epoch", num_train_epochs=num_epochs, save_total_limit=10, per_device_eval_batch_size=eval_batchsize, predict_with_generate=True, generation_max_length=225, logging_steps=500, report_to=["tensorboard"], load_best_model_at_end=True, metric_for_best_model="wer", greater_is_better=False, optim="adamw_bnb_8bit", resume_from_checkpoint= resume_from_ckpt, )
elif train_strategy == 'steps': training_args = Seq2SeqTrainingArguments( output_dir=output_dir, per_device_train_batch_size=train_batchsize, gradient_accumulation_steps=1, learning_rate=learning_rate, warmup_steps=warmup, gradient_checkpointing=gradient_checkpointing, fp16=True, evaluation_strategy="steps", eval_steps=50, save_strategy="steps", save_steps=50, max_steps=num_steps, save_total_limit=10, per_device_eval_batch_size=eval_batchsize, predict_with_generate=True, generation_max_length=225, logging_steps=500, report_to=["tensorboard"], load_best_model_at_end=True, metric_for_best_model="wer", greater_is_better=False, optim="adamw_bnb_8bit", resume_from_checkpoint=resume_from_ckpt, )
trainer = Seq2SeqTrainer( args=training_args, model=model, train_dataset=raw_dataset["train"], eval_dataset=raw_dataset["eval"], data_collator=data_collator, compute_metrics=compute_metrics, tokenizer=processor.feature_extractor, )
processor.save_pretrained(output_dir) model.save_pretrained(output_dir) print('TRAINING IN PROGRESS...') trainer.train() print('DONE TRAINING')
This was the code, please help