[Python] Trained model has "training_args.bin" along with other essentials but I don't see...

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm training a model, and the output includes training_args.bin along with other essential files. However, I don't see a pytorch_model.bin file. From what I've read and gathered through GPT, that file is supposed to be present. Despite this, the model seems to work—I’ve tried generating prompts, and it responds as expected. I'm planning to upload it to HuggingFace, but I’d appreciate it if someone could check whether there's actually an issue.

    Here's my training code:

    from transformers import GPT2Tokenizer, GPT2LMHeadModel, Trainer, TrainingArguments, DataCollatorForLanguageModeling
    from datasets import load_from_disk

    # Load the dataset from disk
    dataset = load_from_disk("./kipling_dataset")

    # Load the tokenizer
    tokenizer = GPT2Tokenizer.from_pretrained("gpt2")

    # Load the previously trained model
    model = GPT2LMHeadModel.from_pretrained("gpt2") # Load the saved model

    # Ensure tokenizer has padding token
    tokenizer.pad_token = tokenizer.eos_token
    model.resize_token_embeddings(len(tokenizer))

    # Data collator for language modeling
    data_collator = DataCollatorForLanguageModeling(
    tokenizer=tokenizer, mlm=False
    )

    # Define training arguments
    training_args = TrainingArguments(
    output_dir="./aikipling_model", # Save model to this directory
    overwrite_output_dir=True, # Overwrite existing model
    num_train_epochs=5, # Train for 5 epochs (you can adjust this based on your data size)
    per_device_train_batch_size=4, # Adjust batch size (you can try increasing this if you have sufficient memory)
    save_steps=500, # Save model every 500 steps
    save_total_limit=2, # Limit saved models to the last 2
    logging_dir="./logs", # Directory for logs
    logging_steps=100, # Log every 100 steps
    fp16=False, # Set to True if you're using a GPU that supports FP16
    )


    # Initialize Trainer
    trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=dataset,
    tokenizer=tokenizer,
    data_collator=data_collator,
    )

    # Start training
    trainer.train()

    # Save final model
    trainer.save_model("./aikipling_model_final")
    tokenizer.save_pretrained("./aikipling_model_final")

    Continue reading...

Compartilhe esta Página