aligntune 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aligntune/__init__.py +368 -0
- aligntune/__main__.py +11 -0
- aligntune/_fallbacks.py +132 -0
- aligntune/_imports.py +598 -0
- aligntune/backends/__init__.py +64 -0
- aligntune/backends/trl/__init__.py +55 -0
- aligntune/backends/trl/eval/__init__.py +0 -0
- aligntune/backends/trl/rewards/__init__.py +27 -0
- aligntune/backends/trl/rewards/training.py +838 -0
- aligntune/backends/trl/rl/__init__.py +53 -0
- aligntune/backends/trl/rl/counterfact_grpo/__init__.py +11 -0
- aligntune/backends/trl/rl/counterfact_grpo/counterfact_grpo.py +1283 -0
- aligntune/backends/trl/rl/counterfact_grpo/custom_trainer.py +2101 -0
- aligntune/backends/trl/rl/dapo/__init__.py +11 -0
- aligntune/backends/trl/rl/dapo/dapo.py +1003 -0
- aligntune/backends/trl/rl/dpo/__init__.py +11 -0
- aligntune/backends/trl/rl/dpo/dpo.py +668 -0
- aligntune/backends/trl/rl/dr_grpo/__init__.py +11 -0
- aligntune/backends/trl/rl/dr_grpo/drgrpo.py +939 -0
- aligntune/backends/trl/rl/gbmpo/__init__.py +3 -0
- aligntune/backends/trl/rl/gbmpo/gbmpo.py +1116 -0
- aligntune/backends/trl/rl/gbmpo/gbmpo_trainer.py +1826 -0
- aligntune/backends/trl/rl/grpo/__init__.py +11 -0
- aligntune/backends/trl/rl/grpo/grpo.py +1105 -0
- aligntune/backends/trl/rl/gspo/__init__.py +11 -0
- aligntune/backends/trl/rl/gspo/gspo.py +1381 -0
- aligntune/backends/trl/rl/meta_es/es_utils.py +446 -0
- aligntune/backends/trl/rl/meta_es/logging_config.py +70 -0
- aligntune/backends/trl/rl/meta_es/meta_es_trainer.py +172 -0
- aligntune/backends/trl/rl/meta_es/meta_es_trainer_utils.py +673 -0
- aligntune/backends/trl/rl/meta_es/neural_mirror_grpo.py +726 -0
- aligntune/backends/trl/rl/meta_es/train_nmdrgrpo_code.py +1523 -0
- aligntune/backends/trl/rl/meta_es/train_nmdrgrpo_es_math.py +635 -0
- aligntune/backends/trl/rl/meta_es/vllm_evaluator.py +674 -0
- aligntune/backends/trl/rl/meta_es/vllm_evaluator_math.py +489 -0
- aligntune/backends/trl/rl/neural_mirror_grpo/NMGrpo.py +941 -0
- aligntune/backends/trl/rl/neural_mirror_grpo/neural_mirror_grpo.py +726 -0
- aligntune/backends/trl/rl/pace/__init__.py +49 -0
- aligntune/backends/trl/rl/pace/baseline.py +549 -0
- aligntune/backends/trl/rl/pace/curriculum.py +467 -0
- aligntune/backends/trl/rl/pace/pace.py +981 -0
- aligntune/backends/trl/rl/ppo/__init__.py +11 -0
- aligntune/backends/trl/rl/ppo/ppo.py +1235 -0
- aligntune/backends/trl/sft/Classification_trainer.py +787 -0
- aligntune/backends/trl/sft/__init__.py +11 -0
- aligntune/backends/trl/sft/sft.py +1659 -0
- aligntune/backends/unsloth/__init__.py +44 -0
- aligntune/backends/unsloth/eval/__init__.py +0 -0
- aligntune/backends/unsloth/rl/__init__.py +36 -0
- aligntune/backends/unsloth/rl/bolt/__init__.py +18 -0
- aligntune/backends/unsloth/rl/bolt/bolt.py +695 -0
- aligntune/backends/unsloth/rl/counterfact_grpo/__init__.py +11 -0
- aligntune/backends/unsloth/rl/counterfact_grpo/counterfact_grpo.py +960 -0
- aligntune/backends/unsloth/rl/dapo/__init__.py +9 -0
- aligntune/backends/unsloth/rl/dapo/dapo.py +1060 -0
- aligntune/backends/unsloth/rl/dpo/__init__.py +9 -0
- aligntune/backends/unsloth/rl/dpo/dpo.py +712 -0
- aligntune/backends/unsloth/rl/dr_grpo/__init__.py +9 -0
- aligntune/backends/unsloth/rl/dr_grpo/drgrpo.py +963 -0
- aligntune/backends/unsloth/rl/gbmpo/__init__.py +3 -0
- aligntune/backends/unsloth/rl/gbmpo/gbmpo.py +1216 -0
- aligntune/backends/unsloth/rl/gbmpo/gbmpo_trainer.py +1826 -0
- aligntune/backends/unsloth/rl/grpo/__init__.py +9 -0
- aligntune/backends/unsloth/rl/grpo/grpo.py +1108 -0
- aligntune/backends/unsloth/rl/gspo/__init__.py +9 -0
- aligntune/backends/unsloth/rl/gspo/gspo.py +1279 -0
- aligntune/backends/unsloth/rl/neural_mirror_grpo/NMGrpo.py +1140 -0
- aligntune/backends/unsloth/rl/neural_mirror_grpo/neural_mirror_grpo.py +726 -0
- aligntune/backends/unsloth/rl/ppo/__init__.py +76 -0
- aligntune/backends/unsloth/rl/ppo/ppo.py +2345 -0
- aligntune/backends/unsloth/rl/ppo/unsloth_patches.py +355 -0
- aligntune/backends/unsloth/sft/__init__.py +9 -0
- aligntune/backends/unsloth/sft/sft.py +1203 -0
- aligntune/cli/__init__.py +95 -0
- aligntune/cli/__main__.py +10 -0
- aligntune/cli/arg_parser.py +442 -0
- aligntune/cli/config_builders.py +469 -0
- aligntune/cli/diagnose.py +367 -0
- aligntune/cli/finetune.py +508 -0
- aligntune/cli/recipes.py +320 -0
- aligntune/cli/unified-old.py +1135 -0
- aligntune/cli/unified.py +1679 -0
- aligntune/cli/validate.py +511 -0
- aligntune/core/backend_factory.py +1320 -0
- aligntune/core/callbacks/__init__.py +7 -0
- aligntune/core/callbacks/base.py +165 -0
- aligntune/core/dataset_adapters.py +361 -0
- aligntune/core/optimization.py +424 -0
- aligntune/core/precision_handler.py +207 -0
- aligntune/core/rl/__init__.py +65 -0
- aligntune/core/rl/caching.py +324 -0
- aligntune/core/rl/config.py +729 -0
- aligntune/core/rl/config_loader.py +307 -0
- aligntune/core/rl/distributed.py +319 -0
- aligntune/core/rl/evaluator.py +1053 -0
- aligntune/core/rl/function_based_reward_model.py +276 -0
- aligntune/core/rl/logging.py +327 -0
- aligntune/core/rl/models.py +371 -0
- aligntune/core/rl/registries.py +631 -0
- aligntune/core/rl/reward_model_wrapper.py +212 -0
- aligntune/core/rl/rollout.py +412 -0
- aligntune/core/rl/sample_logger.py +135 -0
- aligntune/core/rl/trainer_base.py +920 -0
- aligntune/core/rl/trainer_factory.py +152 -0
- aligntune/core/sft/__init__.py +44 -0
- aligntune/core/sft/config.py +762 -0
- aligntune/core/sft/config_loader.py +174 -0
- aligntune/core/sft/evaluator.py +1017 -0
- aligntune/core/sft/logging.py +117 -0
- aligntune/core/sft/trainer_base.py +601 -0
- aligntune/core/sft/trainer_factory.py +78 -0
- aligntune/data/__init__.py +0 -0
- aligntune/data/full_requirements_test.py +201 -0
- aligntune/data/loaders/__init__.py +0 -0
- aligntune/data/loaders/base.py +7 -0
- aligntune/data/loaders/csv_loader.py +20 -0
- aligntune/data/loaders/directory_loader.py +27 -0
- aligntune/data/loaders/hf_loader.py +45 -0
- aligntune/data/loaders/json_loader.py +12 -0
- aligntune/data/loaders/parquet_loader.py +9 -0
- aligntune/data/loaders/resolver.py +33 -0
- aligntune/data/manager.py +214 -0
- aligntune/data/processors.py +675 -0
- aligntune/data/schemas.py +90 -0
- aligntune/eval/__init__.py +113 -0
- aligntune/eval/caching.py +40 -0
- aligntune/eval/cli.py +248 -0
- aligntune/eval/core.py +419 -0
- aligntune/eval/evaluator.py +492 -0
- aligntune/eval/full_evaluation_test.py +228 -0
- aligntune/eval/lm_eval_integration.py +443 -0
- aligntune/eval/metrics/__init__.py +22 -0
- aligntune/eval/metrics/base.py +45 -0
- aligntune/eval/metrics/code.py +249 -0
- aligntune/eval/metrics/dpo.py +372 -0
- aligntune/eval/metrics/generic.py +52 -0
- aligntune/eval/metrics/math.py +139 -0
- aligntune/eval/metrics/rl.py +57 -0
- aligntune/eval/metrics/text.py +128 -0
- aligntune/eval/registry.py +56 -0
- aligntune/eval/rl_evaluator.py +573 -0
- aligntune/eval/runner.py +751 -0
- aligntune/eval/safe_executor.py +509 -0
- aligntune/main.py +1024 -0
- aligntune/py.typed +0 -0
- aligntune/recipes/__init__.py +538 -0
- aligntune/recipes/config.py +22 -0
- aligntune/rewards/__init__.py +69 -0
- aligntune/rewards/core.py +3161 -0
- aligntune/rewards/factory.py +162 -0
- aligntune/rewards/registry.py +528 -0
- aligntune/rewards/training.py +804 -0
- aligntune/rl/__init__.py +10 -0
- aligntune/rl/core/__init__.py +10 -0
- aligntune/scripts/__init__.py +3 -0
- aligntune/scripts/precompute_baseline.py +1937 -0
- aligntune/sft/__init__.py +10 -0
- aligntune/sft/core/__init__.py +10 -0
- aligntune/utils/__init__.py +132 -0
- aligntune/utils/auth.py +239 -0
- aligntune/utils/checkpointing.py +439 -0
- aligntune/utils/colored_logging.py +259 -0
- aligntune/utils/config_extractor.py +346 -0
- aligntune/utils/config_utils.py +501 -0
- aligntune/utils/device.py +425 -0
- aligntune/utils/diagnostics.py +454 -0
- aligntune/utils/environment.py +278 -0
- aligntune/utils/errors.py +429 -0
- aligntune/utils/inference_utils.py +40 -0
- aligntune/utils/logging.py +301 -0
- aligntune/utils/math_grading.py +758 -0
- aligntune/utils/model_loader.py +577 -0
- aligntune/utils/validation.py +514 -0
- aligntune-0.2.0.dist-info/METADATA +306 -0
- aligntune-0.2.0.dist-info/RECORD +179 -0
- aligntune-0.2.0.dist-info/WHEEL +5 -0
- aligntune-0.2.0.dist-info/entry_points.txt +25 -0
- aligntune-0.2.0.dist-info/licenses/LICENSE +21 -0
- aligntune-0.2.0.dist-info/top_level.txt +1 -0
aligntune/__init__.py
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AlignTune: A comprehensive fine-tuning library supporting both SFT and RL training methods.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
# Import colored logging utilities
|
|
10
|
+
try:
|
|
11
|
+
from .utils.colored_logging import (
|
|
12
|
+
init_aligntune_logging,
|
|
13
|
+
print_aligntune_banner,
|
|
14
|
+
print_section_banner,
|
|
15
|
+
print_subsection,
|
|
16
|
+
aligntune_info,
|
|
17
|
+
aligntune_warning,
|
|
18
|
+
aligntune_error,
|
|
19
|
+
aligntune_success,
|
|
20
|
+
aligntune_step,
|
|
21
|
+
setup_colored_logging,
|
|
22
|
+
)
|
|
23
|
+
COLORED_LOGGING_AVAILABLE = True
|
|
24
|
+
except ImportError:
|
|
25
|
+
COLORED_LOGGING_AVAILABLE = False
|
|
26
|
+
# Fallback to basic logging
|
|
27
|
+
if not logging.getLogger().handlers:
|
|
28
|
+
logging.basicConfig(level=logging.INFO)
|
|
29
|
+
logger = logging.getLogger("aligntune")
|
|
30
|
+
logger.setLevel(logging.WARNING)
|
|
31
|
+
|
|
32
|
+
# Initialize colored logging if available
|
|
33
|
+
if COLORED_LOGGING_AVAILABLE:
|
|
34
|
+
logger = setup_colored_logging("aligntune", logging.WARNING)
|
|
35
|
+
else:
|
|
36
|
+
# Configure basic logging as fallback
|
|
37
|
+
if not logging.getLogger().handlers:
|
|
38
|
+
logging.basicConfig(level=logging.INFO)
|
|
39
|
+
logger = logging.getLogger("aligntune")
|
|
40
|
+
logger.setLevel(logging.WARNING)
|
|
41
|
+
|
|
42
|
+
# -----------------------------------------------------------------------------
|
|
43
|
+
# VERSION & METADATA
|
|
44
|
+
# -----------------------------------------------------------------------------
|
|
45
|
+
try:
|
|
46
|
+
from importlib.metadata import version as _pkg_version, PackageNotFoundError as _PkgNotFound
|
|
47
|
+
__version__ = _pkg_version("aligntune")
|
|
48
|
+
except Exception: # Fallback during editable installs before metadata exists
|
|
49
|
+
__version__ = "0.0.0"
|
|
50
|
+
__author__ = "Your Name"
|
|
51
|
+
__email__ = "your.email@example.com"
|
|
52
|
+
|
|
53
|
+
# -----------------------------------------------------------------------------
|
|
54
|
+
# CORE IMPORTS
|
|
55
|
+
# -----------------------------------------------------------------------------
|
|
56
|
+
# Import all components from the centralized import management system
|
|
57
|
+
from ._imports import (
|
|
58
|
+
# Core availability flags
|
|
59
|
+
UNSLOTH_AVAILABLE,
|
|
60
|
+
UNSLOTH_ERROR_INFO,
|
|
61
|
+
TRL_AVAILABLE,
|
|
62
|
+
UNIFIED_RL_AVAILABLE,
|
|
63
|
+
UNIFIED_SFT_AVAILABLE,
|
|
64
|
+
EVAL_AVAILABLE,
|
|
65
|
+
REWARDS_AVAILABLE,
|
|
66
|
+
BACKEND_FACTORY_AVAILABLE,
|
|
67
|
+
UNIFIED_AVAILABLE,
|
|
68
|
+
CLI_AVAILABLE,
|
|
69
|
+
|
|
70
|
+
# Unified system components
|
|
71
|
+
UnifiedConfig,
|
|
72
|
+
AlgorithmType,
|
|
73
|
+
PrecisionType,
|
|
74
|
+
BackendType,
|
|
75
|
+
UnifiedModelConfig,
|
|
76
|
+
UnifiedDatasetConfig,
|
|
77
|
+
RewardConfig,
|
|
78
|
+
UnifiedTrainingConfig,
|
|
79
|
+
DistributedConfig,
|
|
80
|
+
UnifiedLoggingConfig,
|
|
81
|
+
ConfigLoader,
|
|
82
|
+
TrainerBase,
|
|
83
|
+
TrainingState,
|
|
84
|
+
TrainerFactory,
|
|
85
|
+
DatasetRegistry,
|
|
86
|
+
RewardRegistry,
|
|
87
|
+
TaskRegistry,
|
|
88
|
+
UnifiedLogger,
|
|
89
|
+
UnifiedEvaluator,
|
|
90
|
+
PolicyModel,
|
|
91
|
+
ReferenceModel,
|
|
92
|
+
ValueModel,
|
|
93
|
+
RolloutEngine,
|
|
94
|
+
# Optimization components
|
|
95
|
+
OptimizerRegistry,
|
|
96
|
+
SchedulerRegistry,
|
|
97
|
+
OptimizerType,
|
|
98
|
+
SchedulerType,
|
|
99
|
+
get_optimizer_for_config,
|
|
100
|
+
get_scheduler_for_config,
|
|
101
|
+
validate_optimizer_availability,
|
|
102
|
+
validate_scheduler_availability,
|
|
103
|
+
# Recipe system
|
|
104
|
+
RecipeRegistry,
|
|
105
|
+
RecipeTypeEnum,
|
|
106
|
+
ModelFamily,
|
|
107
|
+
RecipeMetadata,
|
|
108
|
+
Recipe,
|
|
109
|
+
load_recipe_from_yaml,
|
|
110
|
+
load_builtin_recipes,
|
|
111
|
+
# Validation and diagnostics
|
|
112
|
+
ConfigValidator,
|
|
113
|
+
validate_config,
|
|
114
|
+
TrainingDiagnostics,
|
|
115
|
+
TrainingMonitor,
|
|
116
|
+
DiagnosticsCollector,
|
|
117
|
+
generate_training_report,
|
|
118
|
+
run_config_validation,
|
|
119
|
+
run_comprehensive_diagnostics,
|
|
120
|
+
# Error handling and UX
|
|
121
|
+
AlignTuneError,
|
|
122
|
+
ConfigurationError,
|
|
123
|
+
TrainingError,
|
|
124
|
+
EnvironmentError,
|
|
125
|
+
ValidationError,
|
|
126
|
+
handle_error,
|
|
127
|
+
create_progress_display,
|
|
128
|
+
HealthMonitor,
|
|
129
|
+
config_error,
|
|
130
|
+
training_error,
|
|
131
|
+
env_error,
|
|
132
|
+
validation_error,
|
|
133
|
+
PPOTrainer,
|
|
134
|
+
DPOTrainer,
|
|
135
|
+
GRPOTrainer,
|
|
136
|
+
GSPOTrainer,
|
|
137
|
+
|
|
138
|
+
# SFT system components
|
|
139
|
+
SFTConfig,
|
|
140
|
+
SFTTaskType,
|
|
141
|
+
SFTModelConfig,
|
|
142
|
+
SFTDatasetConfig,
|
|
143
|
+
SFTTrainingConfig,
|
|
144
|
+
SFTLoggingConfig,
|
|
145
|
+
SFTConfigLoader,
|
|
146
|
+
SFTTrainerFactory,
|
|
147
|
+
InstructionTrainer,
|
|
148
|
+
ClassificationTrainer,
|
|
149
|
+
ChatTrainer,
|
|
150
|
+
|
|
151
|
+
# Evaluation system
|
|
152
|
+
EvalType,
|
|
153
|
+
TaskCategory,
|
|
154
|
+
EvalConfig,
|
|
155
|
+
EvalTask,
|
|
156
|
+
EvalResult,
|
|
157
|
+
EvalRunner,
|
|
158
|
+
LMEvalConfig,
|
|
159
|
+
LMEvalRunner,
|
|
160
|
+
get_available_lm_eval_tasks,
|
|
161
|
+
run_standard_benchmark,
|
|
162
|
+
|
|
163
|
+
# Rewards system
|
|
164
|
+
RewardType,
|
|
165
|
+
RewardConfig as RewardsRewardConfig,
|
|
166
|
+
RewardFunction,
|
|
167
|
+
RewardFunctionFactory,
|
|
168
|
+
CompositeReward,
|
|
169
|
+
rewards_registry,
|
|
170
|
+
|
|
171
|
+
# Backend factory
|
|
172
|
+
BackendFactory,
|
|
173
|
+
TrainingType,
|
|
174
|
+
BackendFactoryType as BackendType,
|
|
175
|
+
FactoryBackendType,
|
|
176
|
+
RLAlgorithm,
|
|
177
|
+
BackendConfig,
|
|
178
|
+
create_sft_trainer,
|
|
179
|
+
create_rl_trainer,
|
|
180
|
+
list_backends,
|
|
181
|
+
|
|
182
|
+
# CLI components
|
|
183
|
+
cli_main,
|
|
184
|
+
|
|
185
|
+
# Helper functions
|
|
186
|
+
get_available_trainers,
|
|
187
|
+
print_available_trainers,
|
|
188
|
+
check_dependencies,
|
|
189
|
+
get_missing_dependencies,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
# Import fallback functions from dedicated module
|
|
193
|
+
from ._fallbacks import (
|
|
194
|
+
train_dpo_from_yaml,
|
|
195
|
+
train_ppo_from_yaml,
|
|
196
|
+
train_grpo_from_yaml,
|
|
197
|
+
train_grpo_from_config,
|
|
198
|
+
create_sample_dpo_config,
|
|
199
|
+
create_minimal_dpo_config,
|
|
200
|
+
create_sample_ppo_config,
|
|
201
|
+
create_minimal_ppo_config,
|
|
202
|
+
create_specialized_ppo_configs,
|
|
203
|
+
load_ppo_config_from_yaml,
|
|
204
|
+
show_ppo_configuration_menu,
|
|
205
|
+
select_ppo_dataset_size,
|
|
206
|
+
create_grpo_configurations,
|
|
207
|
+
select_grpo_config_interactively,
|
|
208
|
+
evaluate_grpo_model,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
# =============================================================================
|
|
212
|
+
# EXPORTS
|
|
213
|
+
# =============================================================================
|
|
214
|
+
|
|
215
|
+
# Core exports that are always available
|
|
216
|
+
__all__ = [
|
|
217
|
+
# Version info
|
|
218
|
+
"__version__",
|
|
219
|
+
"__author__",
|
|
220
|
+
"__email__",
|
|
221
|
+
|
|
222
|
+
# Core availability flags
|
|
223
|
+
"UNSLOTH_AVAILABLE",
|
|
224
|
+
"TRL_AVAILABLE",
|
|
225
|
+
"UNIFIED_RL_AVAILABLE",
|
|
226
|
+
"UNIFIED_SFT_AVAILABLE",
|
|
227
|
+
"EVAL_AVAILABLE",
|
|
228
|
+
"REWARDS_AVAILABLE",
|
|
229
|
+
"BACKEND_FACTORY_AVAILABLE",
|
|
230
|
+
"UNIFIED_AVAILABLE",
|
|
231
|
+
"CLI_AVAILABLE",
|
|
232
|
+
|
|
233
|
+
# Helper functions
|
|
234
|
+
"get_available_trainers",
|
|
235
|
+
"print_available_trainers",
|
|
236
|
+
"check_dependencies",
|
|
237
|
+
"get_missing_dependencies",
|
|
238
|
+
]
|
|
239
|
+
|
|
240
|
+
# Add unified system components if available
|
|
241
|
+
if UNIFIED_AVAILABLE:
|
|
242
|
+
__all__.extend([
|
|
243
|
+
"UnifiedConfig",
|
|
244
|
+
"AlgorithmType",
|
|
245
|
+
"PrecisionType",
|
|
246
|
+
"BackendType",
|
|
247
|
+
"UnifiedModelConfig",
|
|
248
|
+
"UnifiedDatasetConfig",
|
|
249
|
+
"RewardConfig",
|
|
250
|
+
"UnifiedTrainingConfig",
|
|
251
|
+
"DistributedConfig",
|
|
252
|
+
"UnifiedLoggingConfig",
|
|
253
|
+
"ConfigLoader",
|
|
254
|
+
"TrainerBase",
|
|
255
|
+
"TrainingState",
|
|
256
|
+
"TrainerFactory",
|
|
257
|
+
"DatasetRegistry",
|
|
258
|
+
"RewardRegistry",
|
|
259
|
+
"TaskRegistry",
|
|
260
|
+
"UnifiedLogger",
|
|
261
|
+
"UnifiedEvaluator",
|
|
262
|
+
"PolicyModel",
|
|
263
|
+
"ReferenceModel",
|
|
264
|
+
"ValueModel",
|
|
265
|
+
"RolloutEngine",
|
|
266
|
+
# Optimization components
|
|
267
|
+
"OptimizerRegistry",
|
|
268
|
+
"SchedulerRegistry",
|
|
269
|
+
"OptimizerType",
|
|
270
|
+
"SchedulerType",
|
|
271
|
+
"get_optimizer_for_config",
|
|
272
|
+
"get_scheduler_for_config",
|
|
273
|
+
"validate_optimizer_availability",
|
|
274
|
+
"validate_scheduler_availability",
|
|
275
|
+
# Recipe system
|
|
276
|
+
"RecipeRegistry",
|
|
277
|
+
"RecipeTypeEnum",
|
|
278
|
+
"ModelFamily",
|
|
279
|
+
"RecipeMetadata",
|
|
280
|
+
"Recipe",
|
|
281
|
+
"load_recipe_from_yaml",
|
|
282
|
+
"load_builtin_recipes",
|
|
283
|
+
# Validation and diagnostics
|
|
284
|
+
"ConfigValidator",
|
|
285
|
+
"validate_config",
|
|
286
|
+
"TrainingDiagnostics",
|
|
287
|
+
"TrainingMonitor",
|
|
288
|
+
"DiagnosticsCollector",
|
|
289
|
+
"generate_training_report",
|
|
290
|
+
"run_config_validation",
|
|
291
|
+
"run_comprehensive_diagnostics",
|
|
292
|
+
# Error handling and UX
|
|
293
|
+
"AlignTuneError",
|
|
294
|
+
"ConfigurationError",
|
|
295
|
+
"TrainingError",
|
|
296
|
+
"EnvironmentError",
|
|
297
|
+
"ValidationError",
|
|
298
|
+
"handle_error",
|
|
299
|
+
"create_progress_display",
|
|
300
|
+
"HealthMonitor",
|
|
301
|
+
"config_error",
|
|
302
|
+
"training_error",
|
|
303
|
+
"env_error",
|
|
304
|
+
"validation_error",
|
|
305
|
+
"PPOTrainer",
|
|
306
|
+
"DPOTrainer",
|
|
307
|
+
"GRPOTrainer",
|
|
308
|
+
"GSPOTrainer",
|
|
309
|
+
])
|
|
310
|
+
|
|
311
|
+
# Add SFT system components if available
|
|
312
|
+
if UNIFIED_SFT_AVAILABLE:
|
|
313
|
+
__all__.extend([
|
|
314
|
+
"SFTConfig",
|
|
315
|
+
"SFTTaskType",
|
|
316
|
+
"SFTModelConfig",
|
|
317
|
+
"SFTDatasetConfig",
|
|
318
|
+
"SFTTrainingConfig",
|
|
319
|
+
"SFTLoggingConfig",
|
|
320
|
+
"SFTConfigLoader",
|
|
321
|
+
"SFTTrainerFactory",
|
|
322
|
+
"InstructionTrainer",
|
|
323
|
+
"ClassificationTrainer",
|
|
324
|
+
"ChatTrainer",
|
|
325
|
+
])
|
|
326
|
+
|
|
327
|
+
# Add evaluation components if available
|
|
328
|
+
if EVAL_AVAILABLE:
|
|
329
|
+
__all__.extend([
|
|
330
|
+
"EvalType",
|
|
331
|
+
"TaskCategory",
|
|
332
|
+
"EvalConfig",
|
|
333
|
+
"EvalTask",
|
|
334
|
+
"EvalResult",
|
|
335
|
+
"EvalRunner",
|
|
336
|
+
"LMEvalConfig",
|
|
337
|
+
"LMEvalRunner",
|
|
338
|
+
"get_available_lm_eval_tasks",
|
|
339
|
+
"run_standard_benchmark",
|
|
340
|
+
])
|
|
341
|
+
|
|
342
|
+
# Add rewards components if available
|
|
343
|
+
if REWARDS_AVAILABLE:
|
|
344
|
+
__all__.extend([
|
|
345
|
+
"RewardType",
|
|
346
|
+
"RewardsRewardConfig",
|
|
347
|
+
"RewardFunction",
|
|
348
|
+
"RewardFunctionFactory",
|
|
349
|
+
"CompositeReward",
|
|
350
|
+
"rewards_registry",
|
|
351
|
+
])
|
|
352
|
+
|
|
353
|
+
# Add backend factory components if available
|
|
354
|
+
if BACKEND_FACTORY_AVAILABLE:
|
|
355
|
+
__all__.extend([
|
|
356
|
+
"BackendFactory",
|
|
357
|
+
"TrainingType",
|
|
358
|
+
"BackendType",
|
|
359
|
+
"FactoryBackendType",
|
|
360
|
+
"RLAlgorithm",
|
|
361
|
+
"BackendConfig",
|
|
362
|
+
"create_sft_trainer",
|
|
363
|
+
"create_rl_trainer",
|
|
364
|
+
"list_backends",
|
|
365
|
+
|
|
366
|
+
# CLI components
|
|
367
|
+
"cli_main",
|
|
368
|
+
])
|
aligntune/__main__.py
ADDED
aligntune/_fallbacks.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""
|
|
2
|
+
<<<<<<< HEAD
|
|
3
|
+
=======
|
|
4
|
+
Fallback handler module for AlignTune.
|
|
5
|
+
|
|
6
|
+
This module provides fallback functions when dependencies are missing.
|
|
7
|
+
All functions provide clear error messages with installation instructions.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def train_dpo_from_yaml(*args, **kwargs):
|
|
11
|
+
"""Fallback for DPO training when TRL is not available."""
|
|
12
|
+
raise ImportError(
|
|
13
|
+
"DPO training requires TRL. Install with: pip install trl\n"
|
|
14
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
def train_ppo_from_yaml(*args, **kwargs):
|
|
18
|
+
"""Fallback for PPO training when TRL is not available."""
|
|
19
|
+
raise ImportError(
|
|
20
|
+
"PPO training requires TRL. Install with: pip install trl\n"
|
|
21
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def train_grpo_from_yaml(*args, **kwargs):
|
|
25
|
+
"""Fallback for GRPO training when TRL is not available."""
|
|
26
|
+
raise ImportError(
|
|
27
|
+
"GRPO training requires TRL. Install with: pip install trl\n"
|
|
28
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def train_grpo_from_config(*args, **kwargs):
|
|
32
|
+
"""Fallback for GRPO training from config when TRL is not available."""
|
|
33
|
+
raise ImportError(
|
|
34
|
+
"GRPO training requires TRL. Install with: pip install trl\n"
|
|
35
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def create_sample_dpo_config(*args, **kwargs):
|
|
39
|
+
"""Fallback for DPO config creation when TRL is not available."""
|
|
40
|
+
raise ImportError(
|
|
41
|
+
"DPO config creation requires TRL. Install with: pip install trl\n"
|
|
42
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def create_minimal_dpo_config(*args, **kwargs):
|
|
46
|
+
"""Fallback for minimal DPO config when TRL is not available."""
|
|
47
|
+
raise ImportError(
|
|
48
|
+
"DPO config creation requires TRL. Install with: pip install trl\n"
|
|
49
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def create_sample_ppo_config(*args, **kwargs):
|
|
53
|
+
"""Fallback for PPO config creation when TRL is not available."""
|
|
54
|
+
raise ImportError(
|
|
55
|
+
"PPO config creation requires TRL. Install with: pip install trl\n"
|
|
56
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def create_minimal_ppo_config(*args, **kwargs):
|
|
60
|
+
"""Fallback for minimal PPO config when TRL is not available."""
|
|
61
|
+
raise ImportError(
|
|
62
|
+
"PPO config creation requires TRL. Install with: pip install trl\n"
|
|
63
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def create_specialized_ppo_configs(*args, **kwargs):
|
|
67
|
+
"""Fallback for specialized PPO configs when TRL is not available."""
|
|
68
|
+
raise ImportError(
|
|
69
|
+
"PPO config creation requires TRL. Install with: pip install trl\n"
|
|
70
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
def load_ppo_config_from_yaml(*args, **kwargs):
|
|
74
|
+
"""Fallback for PPO config loading when TRL is not available."""
|
|
75
|
+
raise ImportError(
|
|
76
|
+
"PPO config loading requires TRL. Install with: pip install trl\n"
|
|
77
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def show_ppo_configuration_menu(*args, **kwargs):
|
|
81
|
+
"""Fallback for PPO config menu when TRL is not available."""
|
|
82
|
+
raise ImportError(
|
|
83
|
+
"PPO config menu requires TRL. Install with: pip install trl\n"
|
|
84
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def select_ppo_dataset_size(*args, **kwargs):
|
|
88
|
+
"""Fallback for PPO dataset selection when TRL is not available."""
|
|
89
|
+
raise ImportError(
|
|
90
|
+
"PPO dataset selection requires TRL. Install with: pip install trl\n"
|
|
91
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def create_grpo_configurations(*args, **kwargs):
|
|
95
|
+
"""Fallback for GRPO config creation when TRL is not available."""
|
|
96
|
+
raise ImportError(
|
|
97
|
+
"GRPO config creation requires TRL. Install with: pip install trl\n"
|
|
98
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def select_grpo_config_interactively(*args, **kwargs):
|
|
102
|
+
"""Fallback for GRPO config selection when TRL is not available."""
|
|
103
|
+
raise ImportError(
|
|
104
|
+
"GRPO config selection requires TRL. Install with: pip install trl\n"
|
|
105
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
def evaluate_grpo_model(*args, **kwargs):
|
|
109
|
+
"""Fallback for GRPO evaluation when TRL is not available."""
|
|
110
|
+
raise ImportError(
|
|
111
|
+
"GRPO evaluation requires TRL. Install with: pip install trl\n"
|
|
112
|
+
"For more information, visit: https://github.com/huggingface/trl"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# Fallback classes for when trainers are not available
|
|
116
|
+
class FallbackSFTTrainer:
|
|
117
|
+
"""Fallback SFT trainer when trainer is not available."""
|
|
118
|
+
def __init__(self, *args, **kwargs):
|
|
119
|
+
raise ImportError(
|
|
120
|
+
"SFT trainer not available. Check your AlignTune installation.\n"
|
|
121
|
+
"Install with: pip install -e .\n"
|
|
122
|
+
"For more information, visit: https://github.com/yourusername/aligntune"
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
class FallbackClassificationTrainer:
|
|
126
|
+
"""Fallback classification trainer when trainer is not available."""
|
|
127
|
+
def __init__(self, *args, **kwargs):
|
|
128
|
+
raise ImportError(
|
|
129
|
+
"Classification trainer not available. Check your AlignTune installation.\n"
|
|
130
|
+
"Install with: pip install -e .\n"
|
|
131
|
+
"For more information, visit: https://github.com/yourusername/aligntune"
|
|
132
|
+
)
|