()
| 12 | |
| 13 | |
| 14 | def parse_args(): |
| 15 | parser = argparse.ArgumentParser(description="Train a RecurrentDepthTransformer model.") |
| 16 | |
| 17 | # Data paths |
| 18 | parser.add_argument('--data_dir', type=str, default='data/composition.2000.200.7.2', |
| 19 | help='Path to dataset directory') |
| 20 | parser.add_argument('--seed', type=int, default=42) |
| 21 | parser.add_argument('--checkpoint_dir', type=str, default='checkpoints/systematicity/r4', |
| 22 | help='Path to save model checkpoints') |
| 23 | parser.add_argument('--log_file', type=str, default='results/systematicity/r4.txt', |
| 24 | help='Path to save training logs') |
| 25 | |
| 26 | # Training hyperparameters |
| 27 | parser.add_argument('--num_epochs', type=int, default=150001, help='Number of training epochs') |
| 28 | parser.add_argument('--batch_size', type=int, default=128, help='Batch size for training and evaluation') |
| 29 | parser.add_argument('--lr', type=float, default=1e-4, help='Learning rate') |
| 30 | parser.add_argument('--weight_decay', type=float, default=0.1, help='Weight decay for optimizer') |
| 31 | parser.add_argument('--warmup_steps', type=int, default=2000, |
| 32 | help='Number of warmup steps for learning rate scheduler') |
| 33 | |
| 34 | # Model hyperparameters |
| 35 | parser.add_argument('--d_model', type=int, default=768, help='Dimension of model embeddings') |
| 36 | parser.add_argument('--num_recurrent_layers', type=int, default=4, help='Number of recurrent layers') |
| 37 | parser.add_argument('--num_heads', type=int, default=12, help='Number of attention heads') |
| 38 | parser.add_argument('--recurrence', type=int, default=4, help='Number of recurrent iterations') |
| 39 | |
| 40 | parser.add_argument('--use_compile', action='store_true', |
| 41 | help='Enable torch.compile for the model') |
| 42 | parser.add_argument('--compile_mode', type=str, |
| 43 | choices=['default', 'reduce-overhead', 'max-autotune', 'max-autotune-no-cudagraphs'], |
| 44 | default='max-autotune', |
| 45 | help='torch.compile mode') |
| 46 | |
| 47 | # Precision settings |
| 48 | parser.add_argument('--precision', type=str, choices=['fp16', 'bf16'], default='bf16', |
| 49 | help='Enable mixed precision training (fp16 or bf16)') |
| 50 | |
| 51 | # Device configuration |
| 52 | parser.add_argument('--device', type=str, default='cuda' if torch.cuda.is_available() else 'cpu', |
| 53 | help='Device to use for training') |
| 54 | |
| 55 | return parser.parse_args() |
| 56 | |
| 57 | |
| 58 | def train_model(model, dataloader, valid_dataloader, test_dataloader, args): |
no outgoing calls
no test coverage detected