ContrastiveDivergenceTrainer
Methods and Attributes¶
Bases: BaseTrainer
Specialized trainer for contrastive divergence training of EBMs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
energy_function
|
BaseEnergyFunction
|
Energy function to train |
required |
sampler
|
BaseSampler
|
MCMC sampler for generating negative samples |
required |
optimizer
|
Optional[Optimizer]
|
PyTorch optimizer |
None
|
learning_rate
|
float
|
Learning rate (if optimizer not provided) |
0.01
|
k_steps
|
int
|
Number of MCMC steps for generating samples |
10
|
persistent
|
bool
|
Whether to use persistent contrastive divergence (PCD) |
False
|
buffer_size
|
int
|
Replay buffer size for PCD |
1000
|
device
|
Optional[Union[str, device]]
|
Device to run training on |
None
|
dtype
|
dtype
|
Data type for computations |
float32
|
use_mixed_precision
|
bool
|
Whether to use mixed precision training |
False
|
Source code in torchebm/core/base_trainer.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
train_step
¶
Perform a single contrastive divergence training step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Tensor
|
Batch of real data samples |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dictionary containing metrics from this step |