Trainer
gpplus.training.trainer.GPTrainer
¤
Source code in gpplus/training/trainer.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
device = torch.device(device)
instance-attribute
¤
dtype = dtype
instance-attribute
¤
num_epochs = num_epochs
instance-attribute
¤
num_inits = num_inits
instance-attribute
¤
seed = seed
instance-attribute
¤
callbacks = callbacks or []
instance-attribute
¤
cholesky_jitter = cholesky_jitter
instance-attribute
¤
scheduler_class = scheduler_class
instance-attribute
¤
scheduler_kwargs = scheduler_kwargs or {}
instance-attribute
¤
min_epochs = min_epochs
instance-attribute
¤
n_jobs = n_jobs
instance-attribute
¤
inner_max_num_threads = inner_max_num_threads
instance-attribute
¤
stop_conditions = [ConvergencePatienceStopCondition(patience=20), MinLossChangeStopCondition(min_loss_change=1e-07)]
instance-attribute
¤
initializer = DefaultParameterInitializer(num_inits=(self.num_inits), seed=(self.seed))
instance-attribute
¤
optimizer_class = LBFGSScipy
instance-attribute
¤
optimizer_kwargs = optimizer_kwargs or {}
instance-attribute
¤
mll_class = gpytorch.mlls.ExactMarginalLogLikelihood
instance-attribute
¤
__init__(model, optimizer_class: torch.optim.Optimizer = None, optimizer_kwargs: dict = None, scheduler_class: torch.optim.lr_scheduler.LRScheduler = None, scheduler_kwargs: dict = None, num_epochs: int = 1000, seed: int = None, num_inits: int = 64, mll_class: gpytorch.mlls.MarginalLogLikelihood = None, cholesky_jitter: float = 1e-06, callbacks: Optional[List[Callback]] = None, initializer_class: ParameterInitializer = None, initializer_kwargs: dict = None, device: str = 'cpu', stop_conditions: Optional[List[StopCondition]] = None, min_epochs: int = 0, n_jobs: Optional[int] = None, inner_max_num_threads: Optional[int] = 1, dtype: torch.dtype = torch.float64)
¤
Initialize the multi-run GP trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
GP model instance with |
required | |
optimizer_class
|
Optimizer
|
Optimizer class used for each run. Defaults to |
None
|
optimizer_kwargs
|
dict
|
Optimizer kwargs (without |
None
|
scheduler_class
|
LRScheduler
|
Optional learning-rate scheduler class. |
None
|
scheduler_kwargs
|
dict
|
Optional scheduler kwargs. |
None
|
num_epochs
|
int
|
Number of epochs per run. |
1000
|
seed
|
int
|
Random seed for parameter initialization. |
None
|
num_inits
|
int
|
Number of initialization runs to evaluate. |
64
|
mll_class
|
MarginalLogLikelihood
|
Marginal log likelihood class. Defaults to exact MLL. |
None
|
cholesky_jitter
|
float
|
Cholesky jitter used during training. |
1e-06
|
callbacks
|
Optional[List[Callback]]
|
Optional callback instances applied during training. |
None
|
initializer_class
|
ParameterInitializer
|
Parameter initializer class for per-run starts. |
None
|
initializer_kwargs
|
dict
|
Optional kwargs for |
None
|
device
|
str
|
Target device string (falls back to CPU if CUDA is unavailable). |
'cpu'
|
stop_conditions
|
Optional[List[StopCondition]]
|
Optional early-stop conditions. Defaults are applied when omitted. |
None
|
min_epochs
|
int
|
Minimum epochs before stop conditions can terminate a run. |
0
|
n_jobs
|
Optional[int]
|
Optional parallel job cap used by run dispatch. |
None
|
inner_max_num_threads
|
Optional[int]
|
Optional torch thread cap per run worker. |
1
|
dtype
|
dtype
|
Tensor dtype used for model and training data. |
float64
|
Source code in gpplus/training/trainer.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
train_single_process(run_index: int, run_device: Optional[torch.device] = None) -> RunResult
¤
Source code in gpplus/training/trainer.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
train_multiple_process_parallel() -> list[RunResult]
¤
Source code in gpplus/training/trainer.py
221 222 223 224 225 226 227 228 229 | |
train() -> list[RunResult]
¤
Source code in gpplus/training/trainer.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
gpplus.training.training_single_run.GPTrainerSingleProcess
¤
Source code in gpplus/training/training_single_run.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
model = model
instance-attribute
¤
optimizer_class = optimizer_class
instance-attribute
¤
optimizer_kwargs = optimizer_kwargs
instance-attribute
¤
mll_class = mll_class
instance-attribute
¤
num_epochs = num_epochs
instance-attribute
¤
cholesky_jitter = cholesky_jitter
instance-attribute
¤
min_epochs = min_epochs
instance-attribute
¤
callbacks = callbacks or []
instance-attribute
¤
device = torch.device(device) if device is not None else torch.device('cpu')
instance-attribute
¤
scheduler_class = scheduler_class
instance-attribute
¤
scheduler_kwargs = scheduler_kwargs or {}
instance-attribute
¤
scheduler = None
instance-attribute
¤
dtype = dtype
instance-attribute
¤
stop_conditions = [ConvergencePatienceStopCondition(patience=20), MinLossChangeStopCondition(min_loss_change=1e-07)]
instance-attribute
¤
train_x = self.model.train_inputs[0]
instance-attribute
¤
train_y = self.model.train_targets
instance-attribute
¤
__init__(model, optimizer_class, optimizer_kwargs, num_epochs: int, mll_class: gpytorch.mlls.MarginalLogLikelihood = None, cholesky_jitter: float = 1e-06, callbacks: Optional[List[Callback]] = None, device: str | torch.device | None = None, scheduler_class: type[torch.optim.lr_scheduler.LRScheduler] | None = None, scheduler_kwargs: Optional[dict] = None, stop_conditions: Optional[List[StopCondition]] = None, dtype: torch.dtype = torch.float64, min_epochs: int = 0)
¤
Initialize a single training run for one model initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
GP model instance to optimize for this run. |
required | |
optimizer_class
|
Optimizer class used for this run. |
required | |
optimizer_kwargs
|
Optimizer kwargs (without |
required | |
num_epochs
|
int
|
Number of epochs to run for this initialization. |
required |
mll_class
|
MarginalLogLikelihood
|
Marginal log likelihood class used as objective. |
None
|
cholesky_jitter
|
float
|
Cholesky jitter used during the run. |
1e-06
|
callbacks
|
Optional[List[Callback]]
|
Optional callback instances invoked during training. |
None
|
device
|
str | device | None
|
Torch device (or device string) for this run. |
None
|
scheduler_class
|
type[LRScheduler] | None
|
Optional learning-rate scheduler class. |
None
|
scheduler_kwargs
|
Optional[dict]
|
Optional scheduler kwargs. |
None
|
stop_conditions
|
Optional[List[StopCondition]]
|
Optional early-stop conditions for this run. |
None
|
dtype
|
dtype
|
Tensor dtype used in forward/loss computations. |
float64
|
min_epochs
|
int
|
Minimum epochs before stop conditions can terminate training. |
0
|
Source code in gpplus/training/training_single_run.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
train() -> SingleRunResult
¤
Source code in gpplus/training/training_single_run.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
gpplus.training.parameter_initializer.ParameterInitializer
¤
Bases: ABC
Abstract base class for parameter initializers.
Source code in gpplus/training/parameter_initializer.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
__init__(num_inits: int, seed: int = None)
abstractmethod
¤
Source code in gpplus/training/parameter_initializer.py
24 25 26 | |
setup(model: torch.nn.Module)
abstractmethod
¤
Source code in gpplus/training/parameter_initializer.py
28 29 30 | |
initialize(model: torch.nn.Module, run_index: int)
abstractmethod
¤
Source code in gpplus/training/parameter_initializer.py
32 33 34 | |