L
Initializing Studio...
Automated hyperparameter optimization for Large Language Models using advanced search algorithms and neural architecture search techniques.
import langtrain
# Create model with auto-tuning enabled
model = langtrain.Model.create(
name="auto-tuned-classifier",
architecture="bert-base-uncased",
task="classification",
auto_tune=True # Enable auto-tuning
)
# Load your dataset
dataset = langtrain.Dataset.from_csv("data.csv")
# Start auto-tuning
tuner = langtrain.AutoTuner(
model=model,
dataset=dataset,
max_trials=50, # Number of configurations to try
max_epochs=10, # Maximum epochs per trial
objective="f1_score" # Metric to optimize
)
# Run optimization
best_config = tuner.optimize()
print(f"Best configuration: {best_config}")
print(f"Best score: {tuner.best_score}")# Define custom hyperparameter search space
search_space = {
'learning_rate': langtrain.hp.loguniform(1e-6, 1e-3),
'batch_size': langtrain.hp.choice([8, 16, 32, 64]),
'dropout_rate': langtrain.hp.uniform(0.1, 0.5),
'weight_decay': langtrain.hp.loguniform(1e-6, 1e-2),
'warmup_ratio': langtrain.hp.uniform(0.0, 0.2),
'optimizer': langtrain.hp.choice(['adam', 'adamw', 'sgd'])
}
# Configure auto-tuner with custom search space
tuner = langtrain.AutoTuner(
model=model,
dataset=dataset,
search_space=search_space,
algorithm="bayesian", # Optimization algorithm
max_trials=100,
timeout=3600 # 1 hour timeout
)
# Run with early stopping
best_config = tuner.optimize(
early_stopping_patience=10,
min_improvement=0.001
)# Optimize for multiple objectives
objectives = {
'accuracy': 'maximize',
'inference_time': 'minimize',
'model_size': 'minimize'
}
tuner = langtrain.MultiObjectiveTuner(
model=model,
dataset=dataset,
objectives=objectives,
max_trials=200
)
# Get Pareto-optimal solutions
pareto_solutions = tuner.optimize()
# Select best trade-off based on your priorities
best_config = tuner.select_best(
weights={'accuracy': 0.7, 'inference_time': 0.2, 'model_size': 0.1}
)# Use population-based training for dynamic optimization
pbt_config = langtrain.PBTConfig(
population_size=20, # Number of parallel training runs
perturbation_interval=5, # Epochs between perturbations
mutation_rate=0.2, # Probability of parameter mutation
truncation_percentage=0.2 # Bottom 20% get replaced
)
tuner = langtrain.PopulationBasedTuner(
model=model,
dataset=dataset,
config=pbt_config,
total_epochs=50
)
# This will train multiple models simultaneously
# and evolve their hyperparameters over time
results = tuner.train_population()
# Get the best performing model
best_model = results.best_model
best_hyperparams = results.best_hyperparams