ltr 0.1.0
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.
- checksums.yaml +7 -0
- data/ARCHITECTURE.md +92 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +186 -0
- data/docs/AGENTS.md +67 -0
- data/docs/aggregation-engines.md +80 -0
- data/docs/config.md +516 -0
- data/docs/data-contracts.md +94 -0
- data/docs/data-splits.md +34 -0
- data/docs/dataset-builder-steps.md +13 -0
- data/docs/dataset-csv.md +73 -0
- data/docs/dataset-enrichers.md +62 -0
- data/docs/errors.md +33 -0
- data/docs/feature-selection.md +108 -0
- data/docs/features.md +202 -0
- data/docs/glossary.md +56 -0
- data/docs/host-integration.md +128 -0
- data/docs/host-run-pipelines.md +48 -0
- data/docs/index.md +50 -0
- data/docs/inference.md +164 -0
- data/docs/label-transformers.md +242 -0
- data/docs/labels-from-behavior.md +94 -0
- data/docs/learning-to-rank.md +119 -0
- data/docs/metrics.md +166 -0
- data/docs/model-files.md +73 -0
- data/docs/optimization.md +72 -0
- data/docs/public-api.md +67 -0
- data/docs/rake-tasks.md +82 -0
- data/docs/relevance-grades.md +80 -0
- data/docs/run-locally.md +584 -0
- data/docs/run-on-aws.md +647 -0
- data/docs/training-objective.md +110 -0
- data/docs/ubi-documents.md +75 -0
- data/docs/ubi-logging.md +125 -0
- data/lib/ltr/README.md +28 -0
- data/lib/ltr/configuration/README.md +12 -0
- data/lib/ltr/configuration/config_loader.rb +326 -0
- data/lib/ltr/configuration/config_validator.rb +476 -0
- data/lib/ltr/configuration/configuration.rb +84 -0
- data/lib/ltr/configuration/example_config.yml +182 -0
- data/lib/ltr/data/README.md +20 -0
- data/lib/ltr/data/csv/README.md +9 -0
- data/lib/ltr/data/csv/typed_columns.rb +101 -0
- data/lib/ltr/data/csv.rb +126 -0
- data/lib/ltr/data/dataframe.rb +80 -0
- data/lib/ltr/data/dataset_loader.rb +29 -0
- data/lib/ltr/data/row_store.rb +188 -0
- data/lib/ltr/data/split_cache.rb +30 -0
- data/lib/ltr/data/splits.rb +86 -0
- data/lib/ltr/dataset_aggregation/README.md +32 -0
- data/lib/ltr/dataset_aggregation/aggregated_sqlite_loader.rb +64 -0
- data/lib/ltr/dataset_aggregation/cascade_actions.rb +58 -0
- data/lib/ltr/dataset_aggregation/column_name.rb +47 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/README.md +15 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/context.rb +159 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/README.md +16 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/behavioural_feature_builder.rb +77 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/dataset_filters.rb +29 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/label_creator.rb +125 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/negative_downsampler.rb +52 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/query_aggregator.rb +163 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/split_assigner.rb +76 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/ubi_joiner.rb +137 -0
- data/lib/ltr/dataset_aggregation/dataset_builder/steps/user_query_aggregator.rb +68 -0
- data/lib/ltr/dataset_aggregation/dataset_builder.rb +82 -0
- data/lib/ltr/dataset_aggregation/dataset_enricher.rb +168 -0
- data/lib/ltr/dataset_aggregation/dataset_finalizer.rb +116 -0
- data/lib/ltr/dataset_aggregation/dataset_pipeline.rb +113 -0
- data/lib/ltr/dataset_aggregation/dataset_saver.rb +79 -0
- data/lib/ltr/dataset_aggregation/derived_features.rb +45 -0
- data/lib/ltr/dataset_aggregation/display_positions.rb +25 -0
- data/lib/ltr/dataset_aggregation/dropped_events.rb +29 -0
- data/lib/ltr/dataset_aggregation/labels/README.md +18 -0
- data/lib/ltr/dataset_aggregation/labels/identity_label_transformer.rb +11 -0
- data/lib/ltr/dataset_aggregation/labels/label_transformer.rb +61 -0
- data/lib/ltr/dataset_aggregation/labels/log_plus_one_label_transformer.rb +18 -0
- data/lib/ltr/dataset_aggregation/labels/per_query_k_means_label_transformer.rb +141 -0
- data/lib/ltr/dataset_aggregation/labels/per_query_label_transformer.rb +52 -0
- data/lib/ltr/dataset_aggregation/labels/per_query_min_max_label_transformer.rb +27 -0
- data/lib/ltr/dataset_aggregation/labels/quantile_label_transformer.rb +73 -0
- data/lib/ltr/dataset_aggregation/labels/sqrt_label_transformer.rb +18 -0
- data/lib/ltr/dataset_aggregation/missing_hit_ids.rb +20 -0
- data/lib/ltr/dataset_aggregation/negative_rank.rb +15 -0
- data/lib/ltr/dataset_aggregation/sql/aggregate.sqlite.sql.erb +209 -0
- data/lib/ltr/dataset_aggregation/sqlite_aggregator.rb +167 -0
- data/lib/ltr/dataset_aggregation/sqlite_event_stager.rb +79 -0
- data/lib/ltr/dataset_aggregation/sqlite_query_stager.rb +148 -0
- data/lib/ltr/dataset_aggregation/sqlite_staging.rb +180 -0
- data/lib/ltr/dataset_aggregation/sqlite_ubi_data_loader.rb +91 -0
- data/lib/ltr/dataset_aggregation/ubi_data_loader.rb +138 -0
- data/lib/ltr/dataset_aggregation/ubi_data_loader_base.rb +147 -0
- data/lib/ltr/dataset_aggregation/ubi_query_fields.rb +54 -0
- data/lib/ltr/deploy/README.md +21 -0
- data/lib/ltr/deploy/artifacts/code/inference.py +371 -0
- data/lib/ltr/deploy/artifacts/code/requirements.txt +1 -0
- data/lib/ltr/deploy/feature_extractor.rb +94 -0
- data/lib/ltr/deploy/feature_store_deployer.rb +88 -0
- data/lib/ltr/deploy/local_deployer.rb +61 -0
- data/lib/ltr/deploy/model_packager.rb +90 -0
- data/lib/ltr/deploy/sagemaker_deployer.rb +85 -0
- data/lib/ltr/deploy/sagemaker_endpoint.rb +199 -0
- data/lib/ltr/deploy/ssm_feature_source.rb +35 -0
- data/lib/ltr/errors/README.md +16 -0
- data/lib/ltr/errors/configuration_error.rb +5 -0
- data/lib/ltr/errors/deploy_error.rb +5 -0
- data/lib/ltr/errors/error.rb +5 -0
- data/lib/ltr/errors/invalid_dataset_error.rb +5 -0
- data/lib/ltr/errors/missing_dependency_error.rb +5 -0
- data/lib/ltr/errors/sqlite_error.rb +14 -0
- data/lib/ltr/features/README.md +19 -0
- data/lib/ltr/features/encoders/README.md +10 -0
- data/lib/ltr/features/encoders/enriched_column_encoder.rb +77 -0
- data/lib/ltr/features/encoders/feature_encoder.rb +61 -0
- data/lib/ltr/features/feature_engineering.rb +194 -0
- data/lib/ltr/features/feature_transformer.rb +92 -0
- data/lib/ltr/features/float32_range.rb +20 -0
- data/lib/ltr/features/transform_steps.rb +34 -0
- data/lib/ltr/features/transform_store.rb +123 -0
- data/lib/ltr/inference/README.md +11 -0
- data/lib/ltr/inference/base.rb +52 -0
- data/lib/ltr/inference/local_reranker.rb +147 -0
- data/lib/ltr/inference/sagemaker_client.rb +62 -0
- data/lib/ltr/metrics/README.md +12 -0
- data/lib/ltr/metrics/metric_scores.rb +67 -0
- data/lib/ltr/metrics/metrics.rb +139 -0
- data/lib/ltr/optimize/README.md +25 -0
- data/lib/ltr/optimize/bayesian_optimizer.rb +212 -0
- data/lib/ltr/optimize/candidate_selector.rb +97 -0
- data/lib/ltr/optimize/cholesky_decomposition.rb +81 -0
- data/lib/ltr/optimize/expected_improvement.rb +33 -0
- data/lib/ltr/optimize/feature_selection/README.md +15 -0
- data/lib/ltr/optimize/feature_selection/greedy_backward.rb +38 -0
- data/lib/ltr/optimize/feature_selection/importance_ranked.rb +23 -0
- data/lib/ltr/optimize/feature_selection/rfe.rb +22 -0
- data/lib/ltr/optimize/feature_selection/strategy.rb +112 -0
- data/lib/ltr/optimize/feature_selection/trial.rb +39 -0
- data/lib/ltr/optimize/gaussian_process.rb +125 -0
- data/lib/ltr/optimize/optimization_dataset.rb +16 -0
- data/lib/ltr/optimize/optimize_features.rb +129 -0
- data/lib/ltr/optimize/optimize_hyperparameters.rb +165 -0
- data/lib/ltr/optimize/optimize_pipeline.rb +105 -0
- data/lib/ltr/optimize/search_space.rb +165 -0
- data/lib/ltr/optimize/update_config.rb +196 -0
- data/lib/ltr/ssm/README.md +11 -0
- data/lib/ltr/ssm/loader.rb +61 -0
- data/lib/ltr/ssm/parameter_paths.rb +19 -0
- data/lib/ltr/ssm/saver.rb +76 -0
- data/lib/ltr/support/README.md +13 -0
- data/lib/ltr/support/callable.rb +10 -0
- data/lib/ltr/support/optional_dependency.rb +31 -0
- data/lib/ltr/support/pipeline_result.rb +22 -0
- data/lib/ltr/support/pipeline_task.rb +81 -0
- data/lib/ltr/support/version.rb +7 -0
- data/lib/ltr/tasks/ltr.rake +24 -0
- data/lib/ltr/train/README.md +19 -0
- data/lib/ltr/train/deploy_gate.rb +77 -0
- data/lib/ltr/train/deploy_metric.rb +63 -0
- data/lib/ltr/train/eval_logger.rb +16 -0
- data/lib/ltr/train/evaluation_cache.rb +101 -0
- data/lib/ltr/train/modelling_pipeline.rb +82 -0
- data/lib/ltr/train/optimization_split_report.rb +54 -0
- data/lib/ltr/train/utils.rb +35 -0
- data/lib/ltr/train/xgb_evaluator.rb +96 -0
- data/lib/ltr/train/xgb_trainer.rb +154 -0
- data/lib/ltr/ubi.rb +86 -0
- data/lib/ltr.rb +61 -0
- data/scripts/seed_ubi.rb +75 -0
- metadata +346 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Searches for the best XGBoost hyperparameters with the Bayesian optimizer.
|
|
4
|
+
|
|
5
|
+
class Ltr::Optimize::OptimizeHyperparameters
|
|
6
|
+
extend Ltr::Callable
|
|
7
|
+
|
|
8
|
+
REQUIRED_CONFIG_KEYS = %i[hyperparameters optimization].freeze
|
|
9
|
+
|
|
10
|
+
DEFAULT_ITERATIONS = 50
|
|
11
|
+
DEFAULT_N_INIT = 5
|
|
12
|
+
|
|
13
|
+
def self.optimizer_options(optimization)
|
|
14
|
+
base_options = {
|
|
15
|
+
iterations: optimization.fetch("iterations", DEFAULT_ITERATIONS),
|
|
16
|
+
n_init: optimization.fetch("n_init", DEFAULT_N_INIT),
|
|
17
|
+
}
|
|
18
|
+
config_options = (optimization["bayesian_optimizer"] || {}).transform_keys(&:to_sym).slice(*Ltr::Optimize::BayesianOptimizer::DEFAULT_CONFIG.keys)
|
|
19
|
+
config_options.merge(base_options)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Raises `ArgumentError` when `dataset` is not an `OptimizationDataset` or none of `features` are in the dataframe.
|
|
23
|
+
def initialize(dataset, config, features:)
|
|
24
|
+
raise ArgumentError, "dataset must be an OptimizationDataset" unless dataset.is_a?(Ltr::Optimize::OptimizationDataset)
|
|
25
|
+
|
|
26
|
+
validate_config!(config)
|
|
27
|
+
|
|
28
|
+
@df = dataset.df
|
|
29
|
+
@split_cache = dataset.split_cache
|
|
30
|
+
@early_stopping_split = dataset.early_stopping_split
|
|
31
|
+
@optimization_split = dataset.optimization_split
|
|
32
|
+
@config = config
|
|
33
|
+
@base_hyperparameters = config.hyperparameters.transform_keys(&:to_sym).except(:seed).freeze
|
|
34
|
+
@features = get_features_to_optimize(features).freeze
|
|
35
|
+
raise ArgumentError, "features must not be empty" if @features.empty?
|
|
36
|
+
|
|
37
|
+
read_optimization_settings(config.optimization)
|
|
38
|
+
@nthread = config.nthread
|
|
39
|
+
@evaluation_cache = build_evaluation_cache
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Runs the Bayesian search and returns the base hyperparameters merged with the best sampled values.
|
|
43
|
+
# The keys are symbols. The metric is maximized by minimizing its negative.
|
|
44
|
+
# `iterations` and `n_init` default to 50 and 5. The seed is the top-level `seed`.
|
|
45
|
+
def call
|
|
46
|
+
validate_inputs!
|
|
47
|
+
optimize_hyperparameters
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
attr_reader :df, :config, :base_hyperparameters, :features,
|
|
53
|
+
:hyperparameter_search_space, :metric_to_optimize, :evaluation_cache,
|
|
54
|
+
:split_cache, :nthread, :early_stopping_split, :optimization_split
|
|
55
|
+
|
|
56
|
+
def validate_config!(config)
|
|
57
|
+
raise ArgumentError, "config cannot be nil" unless config
|
|
58
|
+
|
|
59
|
+
missing_keys = REQUIRED_CONFIG_KEYS.reject do |key|
|
|
60
|
+
config.respond_to?(key) && !config.public_send(key).nil?
|
|
61
|
+
end
|
|
62
|
+
raise ArgumentError, "config missing required keys: #{missing_keys.join(", ")}" if missing_keys.any?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def get_features_to_optimize(features)
|
|
66
|
+
features_to_optimize = features.dup
|
|
67
|
+
missing_features = features_to_optimize - df.names
|
|
68
|
+
if missing_features.any?
|
|
69
|
+
logger.warn("The following features are not in the dataframe: #{missing_features}")
|
|
70
|
+
end
|
|
71
|
+
available_features = features_to_optimize - missing_features
|
|
72
|
+
logger.info("Features available for optimization: #{available_features.size} out of #{features_to_optimize.size}")
|
|
73
|
+
available_features
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def read_optimization_settings(optimization)
|
|
77
|
+
@hyperparameter_search_space = optimization.fetch("hyperparameter_search_space")
|
|
78
|
+
@metric_to_optimize = config.metric_to_optimize
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def build_evaluation_cache
|
|
82
|
+
logger.info("Scoring hyperparameter trials on the '#{optimization_split}' split")
|
|
83
|
+
|
|
84
|
+
Ltr::Train::EvaluationCache.for_metric(
|
|
85
|
+
df,
|
|
86
|
+
split: optimization_split,
|
|
87
|
+
config: config,
|
|
88
|
+
metric: metric_to_optimize,
|
|
89
|
+
split_cache: split_cache
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def validate_inputs!
|
|
94
|
+
logger.info("Validating hyperparameter optimization inputs...")
|
|
95
|
+
raise ArgumentError, "base_hyperparameters must be a hash" unless base_hyperparameters.is_a?(Hash)
|
|
96
|
+
raise ArgumentError, "features must be an array of strings" unless features.is_a?(Array) && features.all? { |feature| feature.is_a?(String) }
|
|
97
|
+
Ltr::Metrics::MetricScores.validate_spec!(metric_to_optimize, "optimization.metric_to_optimize")
|
|
98
|
+
Ltr::Optimize::SearchSpace.validate!(hyperparameter_search_space, "optimization.hyperparameter_search_space")
|
|
99
|
+
|
|
100
|
+
logger.info("Hyperparameter optimization inputs validated successfully")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def optimize_hyperparameters
|
|
104
|
+
dtrain, deval = build_dmatrices
|
|
105
|
+
|
|
106
|
+
result = Ltr::Optimize::BayesianOptimizer.call(
|
|
107
|
+
objective: define_objective_function(dtrain, deval),
|
|
108
|
+
param_space: format_search_space,
|
|
109
|
+
**get_optimizer_options
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
optimized_hyperparameters = base_hyperparameters.merge(sampled_hyperparameters(result))
|
|
113
|
+
|
|
114
|
+
logger.info("Final optimized hyperparameters: #{optimized_hyperparameters}")
|
|
115
|
+
optimized_hyperparameters
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def build_dmatrices
|
|
119
|
+
logger.info("Creating train and #{early_stopping_split} DMatrix objects...")
|
|
120
|
+
dtrain = split_cache.dmatrix(Ltr::Data::Splits::TRAIN, features)
|
|
121
|
+
deval = split_cache.dmatrix(early_stopping_split, features)
|
|
122
|
+
logger.info("DMatrix creation completed. Training samples: #{dtrain.num_row}, " \
|
|
123
|
+
"#{early_stopping_split} samples: #{deval.num_row}")
|
|
124
|
+
[dtrain, deval]
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def define_objective_function(dtrain, deval)
|
|
128
|
+
->(sampled_params) do
|
|
129
|
+
sampled_params_sym = sampled_params.transform_keys(&:to_sym)
|
|
130
|
+
candidate_params = base_hyperparameters.merge(sampled_params_sym)
|
|
131
|
+
score = evaluate_hyperparameters(candidate_params, dtrain, deval)
|
|
132
|
+
# The Bayesian optimizer minimizes, but the metric is higher-is-better.
|
|
133
|
+
-score
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def evaluate_hyperparameters(hyperparameters, dtrain, deval)
|
|
138
|
+
eval_params = hyperparameters.dup
|
|
139
|
+
eval_params[:verbose_eval] = false
|
|
140
|
+
|
|
141
|
+
model = Ltr::Train::XgbTrainer.train_model(dtrain, deval, eval_params, seed: config.seed, nthread:)
|
|
142
|
+
@evaluation_cache.evaluate_metric(model, features, metric_to_optimize)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def format_search_space
|
|
146
|
+
hyperparameter_search_space.transform_values do |bounds|
|
|
147
|
+
{ min: bounds["min"], max: bounds["max"] }
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def get_optimizer_options
|
|
152
|
+
merged_options = self.class.optimizer_options(config.optimization).merge(seed: config.seed)
|
|
153
|
+
|
|
154
|
+
logger.info("Optimizer options: #{merged_options}")
|
|
155
|
+
merged_options
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def sampled_hyperparameters(result)
|
|
159
|
+
result[:best_parameters].transform_keys(&:to_sym)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def logger
|
|
163
|
+
Ltr.config.logger
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Runs feature and hyperparameter optimization, then writes the results to the config and SSM.
|
|
4
|
+
|
|
5
|
+
class Ltr::Optimize::OptimizePipeline
|
|
6
|
+
extend Ltr::Callable
|
|
7
|
+
|
|
8
|
+
def initialize(config)
|
|
9
|
+
@config = config
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Selects features, then tunes hyperparameters on the selected features.
|
|
13
|
+
# When SSM is enabled, the SSM hyperparameters replace the config's before the search starts.
|
|
14
|
+
# Then it rewrites the config file, and saves to SSM when SSM is enabled.
|
|
15
|
+
# Returns a `Ltr::PipelineResult` with `features`, `hyperparameters` and `ssm_saved`.
|
|
16
|
+
def call
|
|
17
|
+
logger.info("Starting optimization pipeline")
|
|
18
|
+
|
|
19
|
+
dataframe = load_dataset
|
|
20
|
+
load_hyperparameters_from_ssm
|
|
21
|
+
dataset = Ltr::Optimize::OptimizationDataset.new(dataframe, config)
|
|
22
|
+
|
|
23
|
+
logger.info("Starting feature optimization...")
|
|
24
|
+
features_optimized = Ltr::Optimize::OptimizeFeatures.call(dataset, config)
|
|
25
|
+
|
|
26
|
+
all_features = optimized_all_features(features_optimized)
|
|
27
|
+
hyperparameters_optimized = optimize_hyperparameters(dataset, all_features)
|
|
28
|
+
|
|
29
|
+
logger.info("Updating configuration with optimized parameters...")
|
|
30
|
+
update_config(features_optimized, hyperparameters_optimized, all_features)
|
|
31
|
+
logger.info("Configuration update completed")
|
|
32
|
+
|
|
33
|
+
logger.info("Saving optimized parameters to SSM...")
|
|
34
|
+
ssm_saved = save_to_ssm
|
|
35
|
+
logger.info("Optimization pipeline completed successfully")
|
|
36
|
+
|
|
37
|
+
Ltr::PipelineResult.new(
|
|
38
|
+
features: features_optimized,
|
|
39
|
+
hyperparameters: hyperparameters_optimized,
|
|
40
|
+
ssm_saved: ssm_saved
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Writes the optimized features and hyperparameters to the config object and the config file.
|
|
45
|
+
# The derived features in `features_optimized[:search_time_features]` are written as search time features.
|
|
46
|
+
# `all_features` is written as `optimized_features`, so training uses exactly that list.
|
|
47
|
+
def update_config(features_optimized, hyperparameters_optimized, all_features)
|
|
48
|
+
config.search_time_features = features_optimized[:search_time_features]
|
|
49
|
+
config.feature_store_features = features_optimized[:feature_store_features]
|
|
50
|
+
config.optimized_features = all_features
|
|
51
|
+
config.hyperparameters = hyperparameters_optimized
|
|
52
|
+
config.save!
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Saves the optimized values to SSM when `ssm.enabled` is `true`. Returns true if it saved and false if not.
|
|
56
|
+
# Call this after `update_config` so SSM receives the newly optimized values.
|
|
57
|
+
def save_to_ssm
|
|
58
|
+
if config.ssm_enabled?
|
|
59
|
+
logger.info("SSM is enabled, saving optimized parameters...")
|
|
60
|
+
Ltr::Ssm::Saver.call(config)
|
|
61
|
+
logger.info("Parameters saved to SSM successfully")
|
|
62
|
+
true
|
|
63
|
+
else
|
|
64
|
+
logger.info("SSM is disabled, skipping SSM save")
|
|
65
|
+
false
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
attr_reader :config
|
|
72
|
+
|
|
73
|
+
def load_dataset
|
|
74
|
+
logger.info("Loading dataset for optimization...")
|
|
75
|
+
df = Ltr::Data::DatasetLoader.load(config)
|
|
76
|
+
logger.info("Dataset loaded. Rows: #{df.length}, Columns: #{df.keys.length}")
|
|
77
|
+
df
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def load_hyperparameters_from_ssm
|
|
81
|
+
return unless config.ssm_enabled?
|
|
82
|
+
|
|
83
|
+
Ltr::OptionalDependency.require!("aws-sdk-ssm", feature: "SSM parameters")
|
|
84
|
+
begin
|
|
85
|
+
result = Ltr::Ssm::Loader.call(config, load_hyperparameters: true)
|
|
86
|
+
config.hyperparameters = result[:hyperparameters]
|
|
87
|
+
logger.info("Using SSM hyperparameters for optimization")
|
|
88
|
+
rescue Aws::SSM::Errors::ParameterNotFound
|
|
89
|
+
logger.info("No SSM hyperparameters found, using config values")
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def optimized_all_features(features_optimized)
|
|
94
|
+
(features_optimized[:search_time_features] + features_optimized[:feature_store_features]).uniq
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def optimize_hyperparameters(dataset, all_features)
|
|
98
|
+
logger.info("Starting hyperparameter optimization...")
|
|
99
|
+
Ltr::Optimize::OptimizeHyperparameters.call(dataset, config, features: all_features)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def logger
|
|
103
|
+
Ltr.config.logger
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Defines the hyperparameter ranges and converts points between real values and unit vectors.
|
|
4
|
+
|
|
5
|
+
class Ltr::Optimize::SearchSpace
|
|
6
|
+
LOG_SCALE_MIN_RATIO = 20
|
|
7
|
+
|
|
8
|
+
# Raises `Ltr::ConfigurationError` naming `label` unless `space` is a non-empty hash of name to `{ "min" =>, "max" => }`.
|
|
9
|
+
# Each bound must be a number, and `min` must be at most `max`.
|
|
10
|
+
def self.validate!(space, label)
|
|
11
|
+
raise Ltr::ConfigurationError, "#{label} must be a non-empty hash (got #{space.inspect})" unless space.is_a?(Hash) && space.any?
|
|
12
|
+
|
|
13
|
+
space.each do |name, bounds|
|
|
14
|
+
raise Ltr::ConfigurationError, "#{label}.#{name} must be a hash with min and max (got #{bounds.inspect})" unless bounds.is_a?(Hash)
|
|
15
|
+
|
|
16
|
+
%w[min max].each do |bound|
|
|
17
|
+
raise Ltr::ConfigurationError, "#{label}.#{name}.#{bound} must be a number (got #{bounds[bound].inspect})" unless bounds[bound].is_a?(Numeric)
|
|
18
|
+
end
|
|
19
|
+
raise Ltr::ConfigurationError, "#{label}.#{name} min must be at most max (got #{bounds["min"]} and #{bounds["max"]})" if bounds["min"] > bounds["max"]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# `param_space` maps a name to `{ min:, max: }`. A parameter is an integer when both bounds are integers.
|
|
24
|
+
# It uses a log scale when both bounds are positive and `max / min` is at least `LOG_SCALE_MIN_RATIO`.
|
|
25
|
+
def initialize(param_space, random_seed: nil)
|
|
26
|
+
@parameter_definitions = build_parameter_definitions(param_space)
|
|
27
|
+
@parameter_names = @parameter_definitions.keys
|
|
28
|
+
@random_number_generator = Random.new(random_seed) if random_seed
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Returns a hash of parameter name to a random value inside its range. Both ends are included for integers.
|
|
32
|
+
def random_point
|
|
33
|
+
parameter_values = {}
|
|
34
|
+
|
|
35
|
+
@parameter_names.each do |parameter_name|
|
|
36
|
+
parameter_definition = @parameter_definitions[parameter_name]
|
|
37
|
+
random_value = generate_random_value_for_parameter(parameter_definition)
|
|
38
|
+
parameter_values[parameter_name] = random_value
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
parameter_values
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Returns the parameter values as an array of numbers from 0 to 1, one per parameter, in `param_space` order.
|
|
45
|
+
# A value outside its range is not clamped, so it can fall outside 0 to 1.
|
|
46
|
+
def to_unit_vector(parameter_values)
|
|
47
|
+
unit_vector = []
|
|
48
|
+
|
|
49
|
+
@parameter_names.each do |parameter_name|
|
|
50
|
+
parameter_definition = @parameter_definitions[parameter_name]
|
|
51
|
+
normalized_value = normalize_parameter_to_unit_range(parameter_values[parameter_name], parameter_definition)
|
|
52
|
+
unit_vector << normalized_value
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
unit_vector
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Returns a hash of parameter name to value from an array of numbers from 0 to 1.
|
|
59
|
+
# Integer parameters are rounded and kept inside their bounds. Float parameters are not clamped.
|
|
60
|
+
def from_unit_vector(unit_vector)
|
|
61
|
+
parameter_values = {}
|
|
62
|
+
|
|
63
|
+
@parameter_names.each_with_index do |parameter_name, vector_index|
|
|
64
|
+
parameter_definition = @parameter_definitions[parameter_name]
|
|
65
|
+
unit_value = unit_vector[vector_index]
|
|
66
|
+
parameter_value = scale_unit_value_to_parameter_range(unit_value, parameter_definition)
|
|
67
|
+
parameter_values[parameter_name] = parameter_value
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
parameter_values
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Returns `n` parameter hashes. Each parameter's unit range is cut into `n` equal slices, and each slice is used once.
|
|
74
|
+
# The slices are shuffled separately for each parameter. Log scaled parameters are cut in log space.
|
|
75
|
+
def latin_hypercube_sample(n)
|
|
76
|
+
samples_by_parameter = @parameter_names.map do
|
|
77
|
+
stratified_unit_samples(n).shuffle(random: shuffle_rng)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
samples_by_parameter.transpose.map { |unit_vector| from_unit_vector(unit_vector) }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def build_parameter_definitions(param_space)
|
|
86
|
+
param_space.transform_values do |param_config|
|
|
87
|
+
min_value = param_config[:min]
|
|
88
|
+
max_value = param_config[:max]
|
|
89
|
+
parameter_type = determine_parameter_type(min_value, max_value)
|
|
90
|
+
parameter_scale = determine_parameter_scale(min_value, max_value)
|
|
91
|
+
{ min: min_value, max: max_value, type: parameter_type, scale: parameter_scale }
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def determine_parameter_type(min_value, max_value)
|
|
96
|
+
(min_value.is_a?(Integer) && max_value.is_a?(Integer)) ? :int : :float
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def determine_parameter_scale(min_value, max_value)
|
|
100
|
+
return :linear unless min_value.is_a?(Numeric) && max_value.is_a?(Numeric)
|
|
101
|
+
return :linear unless min_value.positive? && max_value.positive?
|
|
102
|
+
return :linear if max_value.to_f / min_value.to_f < LOG_SCALE_MIN_RATIO
|
|
103
|
+
|
|
104
|
+
:log
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def generate_random_value_for_parameter(parameter_definition)
|
|
108
|
+
if parameter_definition[:type] == :int && parameter_definition[:scale] != :log
|
|
109
|
+
return random_generator.rand(parameter_definition[:min]..parameter_definition[:max])
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
scale_unit_value_to_parameter_range(random_generator.rand, parameter_definition)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def stratified_unit_samples(n)
|
|
116
|
+
(0...n).map { |i| (i + random_generator.rand) / n.to_f }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def random_generator
|
|
120
|
+
@random_number_generator || Random
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def shuffle_rng
|
|
124
|
+
@shuffle_rng ||= @random_number_generator || Random.new
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def normalize_parameter_to_unit_range(parameter_value, parameter_definition)
|
|
128
|
+
min_value = parameter_definition[:min].to_f
|
|
129
|
+
max_value = parameter_definition[:max].to_f
|
|
130
|
+
|
|
131
|
+
if parameter_definition[:scale] == :log
|
|
132
|
+
log_min = Math.log(min_value)
|
|
133
|
+
log_max = Math.log(max_value)
|
|
134
|
+
log_range = log_max - log_min
|
|
135
|
+
log_range.zero? ? 0.0 : (Math.log(parameter_value.to_f) - log_min) / log_range
|
|
136
|
+
else
|
|
137
|
+
range = max_value - min_value
|
|
138
|
+
range.zero? ? 0.0 : (parameter_value.to_f - min_value) / range
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def scale_unit_value_to_parameter_range(unit_value, parameter_definition)
|
|
143
|
+
min_value = parameter_definition[:min].to_f
|
|
144
|
+
max_value = parameter_definition[:max].to_f
|
|
145
|
+
|
|
146
|
+
if parameter_definition[:scale] == :log
|
|
147
|
+
log_min = Math.log(min_value)
|
|
148
|
+
log_max = Math.log(max_value)
|
|
149
|
+
scaled_value = Math.exp(log_min + unit_value.to_f * (log_max - log_min))
|
|
150
|
+
else
|
|
151
|
+
range = max_value - min_value
|
|
152
|
+
scaled_value = min_value + unit_value.to_f * range
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
if parameter_definition[:type] == :int
|
|
156
|
+
convert_to_integer_within_bounds(scaled_value, parameter_definition)
|
|
157
|
+
else
|
|
158
|
+
scaled_value
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def convert_to_integer_within_bounds(scaled_value, parameter_definition)
|
|
163
|
+
scaled_value.round.clamp(parameter_definition[:min], parameter_definition[:max])
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Rewrites the feature, optimized feature and hyperparameter sections of the config file with the optimized values.
|
|
4
|
+
|
|
5
|
+
class Ltr::Optimize::UpdateConfig
|
|
6
|
+
extend Ltr::Callable
|
|
7
|
+
|
|
8
|
+
SEARCH_TIME_FEATURES = %w[search_time_features].freeze
|
|
9
|
+
OPTIMIZED_FEATURES = %w[optimized_features].freeze
|
|
10
|
+
FEATURE_STORE_FEATURES = %w[feature_store features].freeze
|
|
11
|
+
HYPERPARAMETERS = %w[model hyperparameters].freeze
|
|
12
|
+
ONE_LINE_VALUE = /(?:\s*(?:\[[^\]]*\]|\{[^}]*\}))?\s*\z/
|
|
13
|
+
PATTERNS = {
|
|
14
|
+
SEARCH_TIME_FEATURES => /\Asearch_time_features:#{ONE_LINE_VALUE}/,
|
|
15
|
+
OPTIMIZED_FEATURES => /\Aoptimized_features:#{ONE_LINE_VALUE}/,
|
|
16
|
+
FEATURE_STORE_FEATURES => /\A\s{2}features:#{ONE_LINE_VALUE}/,
|
|
17
|
+
HYPERPARAMETERS => /\A\s{2}hyperparameters:#{ONE_LINE_VALUE}/,
|
|
18
|
+
}.freeze
|
|
19
|
+
KEY_LINES = {
|
|
20
|
+
SEARCH_TIME_FEATURES => "search_time_features:",
|
|
21
|
+
OPTIMIZED_FEATURES => "optimized_features:",
|
|
22
|
+
FEATURE_STORE_FEATURES => " features:",
|
|
23
|
+
HYPERPARAMETERS => " hyperparameters:",
|
|
24
|
+
}.freeze
|
|
25
|
+
EMPTY_VALUES = {
|
|
26
|
+
SEARCH_TIME_FEATURES => "[]",
|
|
27
|
+
OPTIMIZED_FEATURES => "[]",
|
|
28
|
+
FEATURE_STORE_FEATURES => "[]",
|
|
29
|
+
HYPERPARAMETERS => "{}",
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
32
|
+
# `paths` limits the rewrite to those sections. A section the file lacks is added.
|
|
33
|
+
def initialize(config, paths:)
|
|
34
|
+
@config = config
|
|
35
|
+
@paths = paths
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Rewrites the `search_time_features`, `optimized_features`, `feature_store.features` and `model.hyperparameters` sections of `config.writable_config_path` from the config object.
|
|
39
|
+
# It matches lines, not YAML. Comments inside a section and sibling keys after it are kept.
|
|
40
|
+
# An empty list is written as `[]` and an empty hash as `{}`. A nil list counts as empty.
|
|
41
|
+
# A missing section goes under its parent key. A missing parent or top-level key goes at the end of the file.
|
|
42
|
+
# Raises `Ltr::ConfigurationError` for a hash or array hyperparameter, a parent with a value on its line such as `model: {}`, or a parent whose children are not indented by two spaces.
|
|
43
|
+
# Raises `ArgumentError` for a nil hyperparameter. Nothing is written when it raises.
|
|
44
|
+
def call
|
|
45
|
+
target_path = config.writable_config_path
|
|
46
|
+
content = File.read(target_path)
|
|
47
|
+
updated_content = replace_sections(content)
|
|
48
|
+
File.write(target_path, updated_content)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
attr_reader :config, :paths
|
|
54
|
+
|
|
55
|
+
def replace_sections(content)
|
|
56
|
+
lines = content.split("\n")
|
|
57
|
+
new_lines = []
|
|
58
|
+
found = []
|
|
59
|
+
line_index = 0
|
|
60
|
+
|
|
61
|
+
while line_index < lines.length
|
|
62
|
+
line = lines[line_index]
|
|
63
|
+
path = paths.find { |candidate| line.match?(PATTERNS.fetch(candidate)) }
|
|
64
|
+
|
|
65
|
+
if path
|
|
66
|
+
found << path
|
|
67
|
+
line_index = replace_section(lines, new_lines, line_index, path)
|
|
68
|
+
else
|
|
69
|
+
new_lines << line
|
|
70
|
+
line_index += 1
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
add_missing_sections(new_lines, paths - found)
|
|
75
|
+
new_lines.join("\n") + "\n"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def section_content(path)
|
|
79
|
+
case path
|
|
80
|
+
when SEARCH_TIME_FEATURES, OPTIMIZED_FEATURES
|
|
81
|
+
Array(config.public_send(path.first)).map { |feature| " - #{format_yaml_value("feature", feature)}" }
|
|
82
|
+
when FEATURE_STORE_FEATURES
|
|
83
|
+
Array(config.feature_store_features).map { |feature| " - #{format_yaml_value("feature", feature)}" }
|
|
84
|
+
when HYPERPARAMETERS
|
|
85
|
+
config.hyperparameters.to_h.map do |key, value|
|
|
86
|
+
raise ArgumentError, "`#{HYPERPARAMETERS.join(".")}.#{key}` is nil. Write `false` or `[]` to clear it." if value.nil?
|
|
87
|
+
|
|
88
|
+
" #{key}: #{format_yaml_value(key, value)}"
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def key_line(path, content)
|
|
94
|
+
content.empty? ? "#{KEY_LINES.fetch(path)} #{EMPTY_VALUES.fetch(path)}" : KEY_LINES.fetch(path)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def add_missing_sections(new_lines, missing_paths)
|
|
98
|
+
missing_paths.each do |path|
|
|
99
|
+
content = section_content(path)
|
|
100
|
+
section = [key_line(path, content), *content]
|
|
101
|
+
parent_index = parent_index(new_lines, path.first) if path.length > 1
|
|
102
|
+
|
|
103
|
+
if parent_index
|
|
104
|
+
new_lines.insert(parent_index + 1, *section)
|
|
105
|
+
else
|
|
106
|
+
new_lines << "" unless new_lines.empty? || new_lines.last.empty?
|
|
107
|
+
new_lines.concat((path.length > 1) ? ["#{path.first}:", *section] : section)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def parent_index(lines, parent)
|
|
113
|
+
index = lines.index { |line| line.match?(/\A#{Regexp.escape(parent)}:\s*(#.*)?\z/) }
|
|
114
|
+
unless index
|
|
115
|
+
if lines.any? { |line| line.match?(/\A#{Regexp.escape(parent)}:/) }
|
|
116
|
+
raise Ltr::ConfigurationError, "`#{parent}` must be a block mapping to add a section to it"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
return
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
child = lines[(index + 1)..].find { |line| !line.strip.empty? && !comment?(line) }
|
|
123
|
+
if child && indent_of(child) > 0 && indent_of(child) != 2
|
|
124
|
+
raise Ltr::ConfigurationError, "`#{parent}` children must be indented by 2 spaces to add a section to it"
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
index
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def replace_section(lines, new_lines, key_index, path)
|
|
131
|
+
end_index = section_end(lines, key_index)
|
|
132
|
+
content = section_content(path)
|
|
133
|
+
new_lines << key_line(path, content)
|
|
134
|
+
new_lines.concat(lines[(key_index + 1)...end_index].select { |line| comment?(line) })
|
|
135
|
+
new_lines.concat(content)
|
|
136
|
+
new_lines << ""
|
|
137
|
+
end_index
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def section_end(lines, key_index)
|
|
141
|
+
key_indent = indent_of(lines[key_index])
|
|
142
|
+
line_index = key_index + 1
|
|
143
|
+
while line_index < lines.length
|
|
144
|
+
line = lines[line_index]
|
|
145
|
+
if line.strip.empty?
|
|
146
|
+
line_index += 1
|
|
147
|
+
elsif comment?(line)
|
|
148
|
+
content_index = next_content_index(lines, line_index)
|
|
149
|
+
break unless content_index && section_line?(lines[content_index], key_indent)
|
|
150
|
+
|
|
151
|
+
line_index = content_index
|
|
152
|
+
else
|
|
153
|
+
break unless section_line?(line, key_indent)
|
|
154
|
+
|
|
155
|
+
line_index += 1
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
line_index
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def section_line?(line, key_indent)
|
|
162
|
+
indent = indent_of(line)
|
|
163
|
+
indent > key_indent || (indent == key_indent && line.lstrip.match?(/\A-(\s|\z)/))
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def next_content_index(lines, line_index)
|
|
167
|
+
((line_index + 1)...lines.length).find { |index| !lines[index].strip.empty? && !comment?(lines[index]) }
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def comment?(line)
|
|
171
|
+
line.lstrip.start_with?("#")
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def indent_of(line)
|
|
175
|
+
line[/\A */].size
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def plain_yaml_string?(value)
|
|
179
|
+
!value.include?(" ") && YAML.safe_load(value) == value
|
|
180
|
+
rescue Psych::Exception
|
|
181
|
+
false
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def format_yaml_value(key, value)
|
|
185
|
+
case value
|
|
186
|
+
when Hash, Array
|
|
187
|
+
raise Ltr::ConfigurationError, "hyperparameter `#{key}` must be a single value, got #{value.class}"
|
|
188
|
+
when String
|
|
189
|
+
plain_yaml_string?(value) ? value : value.to_json
|
|
190
|
+
when TrueClass, FalseClass, Numeric
|
|
191
|
+
value
|
|
192
|
+
else
|
|
193
|
+
value.to_s
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# `lib/ltr/ssm`
|
|
2
|
+
|
|
3
|
+
Reads and writes optimized features and hyperparameters to AWS SSM Parameter Store, letting the optimization pipeline persist results that the training and inference paths can later reuse. Everything here lives in the `Ltr::Ssm::` namespace.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
| File | Purpose |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `loader.rb` | `Ltr::Ssm::Loader` fetches optimized features and hyperparameters from SSM Parameter Store, returning only the requested parameters. |
|
|
10
|
+
| `parameter_paths.rb` | `Ltr::Ssm::ParameterPaths::KEYS` lists the `ssm` config keys that the loader, saver and config validator use. `missing_value?` says which values may be an empty list. |
|
|
11
|
+
| `saver.rb` | `Ltr::Ssm::Saver` persists optimized features and hyperparameters to SSM Parameter Store with the `Intelligent-Tiering` tier so subsequent training runs can reuse them. |
|