shuffle parquet for 1 epoch runs using constant instead of cosine scheduler

#1
by Naphula - opened
Naphula-Archives org

Here is a simple, standalone helper script that loads your parquet dataset, shuffles the rows randomly, resets the internal index, and saves it back.

This completely eliminates "recency bias" so the optimizer doesn't heavily prioritize whatever happened to be at the bottom of the original file.

Save this as shuffle_parquet.py in the same directory:

import os
import pandas as pd

DATASET_PATH = os.path.join(os.getcwd(), "dataset_cache", "unified_dataset.parquet")

def shuffle_dataset():
    if not os.path.exists(DATASET_PATH):
        print(f"Error: Could not find parquet file at {DATASET_PATH}")
        return

    print("Loading parquet dataset...")
    df = pd.read_parquet(DATASET_PATH)
    original_len = len(df)
    
    print(f"Loaded {original_len} rows. Shuffling dataset...")
    # frac=1 samples 100% of the data, random_state=None ensures a new random shuffle every run
    # reset_index(drop=True) prevents old indices from saving as a messy column
    shuffled_df = df.sample(frac=1.0).reset_index(drop=True)
    
    print(f"Saving shuffled dataset back to {DATASET_PATH}...")
    shuffled_df.to_parquet(DATASET_PATH, index=False)
    
    print("Success! Dataset is thoroughly shuffled.")

if __name__ == "__main__":
    shuffle_dataset()

Why run this before your 1-epoch finetune:

  • Since you are utilizing Batch Size = 1 and GAS = 1, the model processes one Q&A pair at a time and adjusts its weights immediately.
  • By shuffling the dataset, hard-coded spatial patterns (like "similar questions are grouped at the start, and hard questions are at the end") are broken up.
  • This ensures that the few gradient updates you have are evenly distributed across all concepts, giving the model a balanced, uniform memory of your dataset.

Sign up or log in to comment