Model Card for Layout-Corrector¶
This package ports Layout-Corrector, a training-free confidence model that corrects layouts generated by LayoutDM, the companion 🧨diffusers-style package for discrete diffusion layout generation.
Model Details¶
Model Description¶
Layout-Corrector refines candidate layouts by running a training-free correction stage on top of LayoutDM, a discrete diffusion generator that samples layout tokens through a denoising loop. It accepts starter layouts or nested LayoutDM samples and returns corrected element boxes, labels, masks, and optional correction traces. Public outputs use normalized center xywh boxes in [0, 1], dataset-local integer labels, a valid-element mask, and id2label.
- Developed by: Shoma Iwai et al.
- Shared by: creative-graphic-design.
- Model type: content-agnostic; task: task-agnostic; conditioning: unconditional, label, label_size, completion, refinement.
- Language(s) (NLP): not applicable.
- License: MIT.
Model Sources¶
- Repository: Layout-Corrector repository
- Paper: arXiv 2409.16689
Supported Checkpoints¶
| Checkpoint | Hub ID | Status |
|---|---|---|
| RICO25 | creative-graphic-design/layout-corrector-rico25 |
not-published |
| PubLayNet | creative-graphic-design/layout-corrector-publaynet |
not-published |
| Crello | creative-graphic-design/layout-corrector-crello |
not-published |
Uses¶
Direct Use¶
Use this package for research inference, conversion checks, and agreement checks against the original implementation for generated layouts.
The primary use case is to combine a LayoutDM generator with a matching Layout-Corrector confidence model:
from layout_corrector import LayoutCorrectorModel, LayoutCorrectorPipeline
from layout_dm import LayoutDMPipeline
layout_dm = LayoutDMPipeline.from_pretrained(
".cache/layout-dm/converted/layoutdm-rico25",
)
corrector = LayoutCorrectorModel.from_pretrained(
".cache/layout-corrector/converted/layout-corrector-rico25-smoke",
subfolder="corrector",
)
# After Hub publication: use "creative-graphic-design/layoutdm-rico25" and
# "creative-graphic-design/layout-corrector-rico25".
pipe = LayoutCorrectorPipeline(layout_dm=layout_dm, corrector=corrector)
out = pipe(
batch_size=1,
seed=0,
sampling="deterministic",
corrector_t_list=(10, 20, 30),
return_intermediates=True,
)
print(out.bbox.shape)
print(out.labels.shape)
print(out.id2label[int(out.labels[out.mask][0])])
print(out.scores.shape)
For that return_intermediates=True call, out.scores stores the
Layout-Corrector confidence scores collected at the selected correction
timesteps.
Without the corrector, LayoutDM samples the next layout tokens directly from its denoiser predictions. With the corrector, low-confidence reconstructed tokens are re-masked at selected timesteps, which gives LayoutDM another chance to regenerate uncertain positions and can reduce layout sticking.
LayoutDM denoiser logits
|
v
reconstruct x0 tokens
|
v
Layout-Corrector confidence score
|
v
re-mask low-confidence tokens
|
v
LayoutDM samples the next step
Conditional generation follows the nested LayoutDM processor path:
condition_type |
Required inputs | Effect |
|---|---|---|
unconditional |
none | samples with nested LayoutDM, then applies correction |
label |
labels, bbox, optional mask |
keeps labels fixed and corrects sampled geometry |
label_size |
labels, bbox, optional mask |
keeps labels and element sizes fixed |
completion |
labels, bbox, optional mask |
preserves provided elements and completes the layout |
refinement |
labels, bbox, optional mask |
refines the provided layout |
text, content_image, relation, hierarchical, retrieval |
not applicable | raises NotImplementedError through nested LayoutDM |
labels = [[1, 2, 3]]
bbox = [[[0.2, 0.2, 0.1, 0.1], [0.5, 0.5, 0.2, 0.2], [0.7, 0.7, 0.1, 0.2]]]
mask = [[True, True, True]]
out = pipe(
condition_type="label",
labels=labels,
bbox=bbox,
mask=mask,
seed=0,
)
print(out.bbox.shape)
Downstream Use¶
Generated layouts may feed rendering, design tooling, layout evaluation, or downstream content placement systems after task-specific validation.
Out-of-Scope Use¶
Do not treat generated layouts as production accessibility annotations, OCR output, semantic scene understanding, or license-cleared design assets without separate review.
Bias, Risks, and Limitations¶
The converted behavior follows the upstream checkpoints, prompt fixtures, and datasets. Dataset coverage, label vocabularies, and layout quality inherit the limits of those sources.
Recommendations¶
Re-run the agreement-check suite against the original implementation before publishing converted checkpoints or comparing new results.
How to Get Started with the Model¶
Install the package directly from this repository. The command includes the shared packages required by the pipeline.
pip install \
"laygen @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=lib/laygen" \
"layout-dm @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=models/layout-dm" \
"layout-corrector @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=models/layout-corrector"
Clone this repository, install the workspace member, and run the download and conversion steps in REPRODUCING.md. Those steps create .cache/layout-corrector/converted/layout-corrector-rico25-smoke.
git clone https://github.com/creative-graphic-design/design-generators.git
cd design-generators
uv sync --package layout-corrector
uv run --package layout-corrector python
from layout_corrector import LayoutCorrectorPipeline
path = ".cache/layout-corrector/converted/layout-corrector-rico25-smoke"
# After Hub publication: from_pretrained("creative-graphic-design/layout-corrector-rico25")
pipe = LayoutCorrectorPipeline.from_pretrained(path)
out = pipe(batch_size=1, seed=0, num_inference_steps=1, sampling="deterministic")
print(out.bbox.shape)
print(out.labels.shape)
print(out.id2label[int(out.labels[out.mask][0])])
Training Details¶
Training Data¶
| Dataset | Dataset ID | Notes |
|---|---|---|
| RICO25 | creative-graphic-design/Rico |
ui-screenshots-and-hierarchies-with-semantic-annotations |
| PubLayNet | creative-graphic-design/PubLayNet |
default |
| Crello | cyberagent/crello |
canonical source until an org mirror exists |
The converted checkpoints follow the original Layout-Corrector release and use the authors' released preprocessing package for exact agreement fixtures. For Crello, cyberagent/crello is the canonical Hugging Face dataset source for processor/data-path documentation; the authors' processed splits remain the agreement baseline because they are the released preprocessing artifact.
Training Procedure¶
This package ports released behavior and does not retrain the method in this repository. Trained-checkpoint S5 reproduction is not claimed; the package evidence covers the ordered S0-S4 agreement checks only.
Preprocessing¶
Inputs and outputs are normalized to the public layout schema at package boundaries. Boxes, tokens, prompts, or analog bits that follow the original implementation stay inside package adapters and fixtures used for agreement checks.
Training Hyperparameters¶
- Training regime: original upstream training; not rerun in this repository.
Speeds, Sizes, Times¶
Training-time and carbon measurements are unknown.
Evaluation¶
Testing Data, Factors & Metrics¶
Testing Data¶
Agreement checks use local-only generated fixtures and converted checkpoint directories. Large generated tensors, images, weights, and downloaded artifacts are not committed.
Factors¶
Agreement results are reported separately by dataset, checkpoint, condition mode, seed, or prompt fixture where the package has recorded evidence.
Metrics¶
Metrics are exact tensor equality, exact token or byte equality, or an explicitly stated numeric tolerance against the original implementation.
Parity Results¶
| Dataset | Seed | Compared path | Cases | Assertion |
|---|---|---|---|---|
| RICO25 | 0 | original-implementation corrector logits vs. converted corrector logits | 1 synthetic batch | torch.allclose(atol=1e-5, rtol=1e-5) |
| RICO25 | 1 | original-implementation corrector logits vs. converted corrector logits | 1 synthetic batch | torch.allclose(atol=1e-5, rtol=1e-5) |
| RICO25 | 2 | original-implementation corrector logits vs. converted corrector logits | 1 synthetic batch | torch.allclose(atol=1e-5, rtol=1e-5) |
| PubLayNet | 0 | original-implementation corrector logits vs. converted corrector logits | 1 synthetic batch | torch.allclose(atol=1e-5, rtol=1e-5) |
| PubLayNet | 1 | original-implementation corrector logits vs. converted corrector logits | 1 synthetic batch | torch.allclose(atol=1e-5, rtol=1e-5) |
| PubLayNet | 2 | original-implementation corrector logits vs. converted corrector logits | 1 synthetic batch | torch.allclose(atol=1e-5, rtol=1e-5) |
| Crello | 0 | original-implementation corrector logits vs. converted corrector logits | 1 synthetic batch | torch.allclose(atol=1e-5, rtol=1e-5) |
| Crello | 1 | original-implementation corrector logits vs. converted corrector logits | 1 synthetic batch | torch.allclose(atol=1e-5, rtol=1e-5) |
| Crello | 2 | original-implementation corrector logits vs. converted corrector logits | 1 synthetic batch | torch.allclose(atol=1e-5, rtol=1e-5) |
Reproducibility¶
See REPRODUCING.md for the commands that download original-implementation assets, generate reference outputs, run agreement checks, convert checkpoints, and smoke-test local loading.
Environmental Impact¶
No new model training is performed by these conversion packages. Conversion and parity costs depend on the selected checkpoint and local hardware.
Technical Specifications¶
Model Architecture and Objective¶
Layout-Corrector combines a base LayoutDM denoising pipeline with a confidence model that scores reconstructed layout tokens. Low-confidence positions can be masked and regenerated during selected timesteps, producing corrected boxes, labels, masks, score tensors, and optional correction traces.
Compute Infrastructure¶
Agreement-check commands are intended for one explicitly selected GPU when the original implementation requires CUDA.
Hardware¶
CPU is sufficient for import and most smoke tests. CUDA is required for heavyweight agreement checks when the original implementation requires it.
Software¶
Use uv run --package layout-corrector ... from the repository root so workspace dependency sources and extras resolve correctly.
License¶
Repository wrapper code is Apache-2.0. The original Layout-Corrector implementation is released under the MIT license. The nested LayoutDM implementation is Apache-2.0.
Citation¶
@article{iwai2024layoutcorrector,
title = {Layout-Corrector: Alleviating Layout Sticking Phenomenon in Discrete Diffusion Model},
author = {Iwai, Shoma and Osanai, Atsuki and Kitada, Shunsuke and Omachi, Shinichiro},
journal = {arXiv preprint arXiv:2409.16689},
year = {2024}
}
API Reference¶
Public Layout-Corrector pipeline, model, config, and sampling exports.
CorrectorPositionEmbedding ¶
Bases: StrEnum
Supported original position-embedding modes.
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
35 36 37 38 39 40 41 42 | |
CorrectorReconType ¶
Bases: StrEnum
Supported Layout-Corrector reconstruction targets.
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
21 22 23 24 25 | |
CorrectorTarget ¶
Bases: StrEnum
Supported Layout-Corrector confidence targets.
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
28 29 30 31 32 | |
CorrectorTransformerType ¶
Bases: StrEnum
Supported corrector transformer variants.
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
45 46 47 48 | |
LayoutCorrectorConfig ¶
Bases: ConfigMixin
Configuration for the Layout-Corrector transformer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias used for labels. |
required |
vocab_size
|
int
|
LayoutDM vocabulary size expected by the corrector. |
required |
id2label
|
dict[int | str, str] | None
|
Optional class-id mapping. When omitted, the shared registry is used. |
None
|
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
num_attributes_per_element
|
int
|
Number of token attributes per element. |
5
|
hidden_size
|
int
|
Transformer hidden dimension. |
464
|
num_attention_heads
|
int
|
Number of attention heads. |
8
|
num_hidden_layers
|
int
|
Number of transformer layers. |
4
|
intermediate_size
|
int
|
Feed-forward hidden dimension. |
1856
|
dropout
|
float
|
Dropout probability. |
0.0
|
timestep_type
|
str | None
|
Timestep conditioning type. |
'adalayernorm'
|
num_timesteps
|
int
|
Number of diffusion training timesteps. |
100
|
recon_type
|
CorrectorReconType | str
|
Reconstruction target used by the corrector. |
x_t_minus_1
|
target
|
CorrectorTarget | str
|
Confidence target type. |
recon_acc
|
attr_loss_weights
|
tuple[float, float, float, float, float]
|
Per-attribute loss weights. |
(1.0, 1.0, 1.0, 1.0, 1.0)
|
use_padding_as_vocab
|
bool
|
Whether padding is part of the modeled vocabulary. |
True
|
pos_emb
|
CorrectorPositionEmbedding | str
|
Position embedding mode from the original implementation. |
none
|
transformer_type
|
CorrectorTransformerType | str
|
Corrector transformer variant. |
aggregated
|
corrector_steps
|
int
|
Number of correction passes per selected timestep. |
1
|
corrector_t_list
|
tuple[int, ...]
|
Explicit timesteps where the corrector is applied. |
(10, 20, 30)
|
corrector_mask_mode
|
CorrectorMaskMode | str
|
Strategy for selecting tokens to remask. |
thresh
|
corrector_mask_threshold
|
float
|
Confidence threshold for threshold masking. |
0.7
|
corrector_temperature
|
float
|
Temperature used for corrector resampling. |
1.0
|
use_gumbel_noise
|
bool
|
Whether to perturb confidence logits. |
True
|
gumbel_temperature
|
float
|
Temperature for confidence Gumbel noise. |
1.0
|
time_adaptive_temperature
|
bool
|
Whether to scale noise by timestep ratio. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a supplied dataset, shape, or option is unsupported. |
Examples:
>>> cfg = LayoutCorrectorConfig(dataset_name="publaynet", vocab_size=100)
>>> cfg.max_token_length
125
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
max_token_length
property
¶
max_token_length: int
Return the flattened token length for one layout sequence.
Returns:
| Type | Description |
|---|---|
int
|
Maximum token count after flattening element attributes. |
Examples:
>>> LayoutCorrectorConfig(dataset_name="publaynet", vocab_size=100).max_token_length
125
__init__ ¶
__init__(
*,
dataset_name: DatasetName | str,
vocab_size: int,
id2label: dict[int | str, str] | None = None,
max_seq_length: int = 25,
num_attributes_per_element: int = 5,
hidden_size: int = 464,
num_attention_heads: int = 8,
num_hidden_layers: int = 4,
intermediate_size: int = 1856,
dropout: float = 0.0,
timestep_type: str | None = "adalayernorm",
num_timesteps: int = 100,
recon_type: CorrectorReconType
| str = CorrectorReconType.x_t_minus_1,
target: CorrectorTarget
| str = CorrectorTarget.recon_acc,
attr_loss_weights: tuple[
float, float, float, float, float
] = (1.0, 1.0, 1.0, 1.0, 1.0),
use_padding_as_vocab: bool = True,
pos_emb: CorrectorPositionEmbedding
| str = CorrectorPositionEmbedding.none,
transformer_type: CorrectorTransformerType
| str = CorrectorTransformerType.aggregated,
corrector_steps: int = 1,
corrector_t_list: tuple[int, ...] = (10, 20, 30),
corrector_mask_mode: CorrectorMaskMode
| str = CorrectorMaskMode.thresh,
corrector_mask_threshold: float = 0.7,
corrector_temperature: float = 1.0,
use_gumbel_noise: bool = True,
gumbel_temperature: float = 1.0,
time_adaptive_temperature: bool = False,
) -> None
Initialize a Layout-Corrector config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias used for labels. |
required |
vocab_size
|
int
|
LayoutDM vocabulary size expected by the corrector. |
required |
id2label
|
dict[int | str, str] | None
|
Optional class-id mapping. |
None
|
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
num_attributes_per_element
|
int
|
Number of token attributes per element. |
5
|
hidden_size
|
int
|
Transformer hidden dimension. |
464
|
num_attention_heads
|
int
|
Number of attention heads. |
8
|
num_hidden_layers
|
int
|
Number of transformer layers. |
4
|
intermediate_size
|
int
|
Feed-forward hidden dimension. |
1856
|
dropout
|
float
|
Dropout probability. |
0.0
|
timestep_type
|
str | None
|
Timestep conditioning type. |
'adalayernorm'
|
num_timesteps
|
int
|
Number of diffusion training timesteps. |
100
|
recon_type
|
CorrectorReconType | str
|
Reconstruction target used by the corrector. |
x_t_minus_1
|
target
|
CorrectorTarget | str
|
Confidence target type. |
recon_acc
|
attr_loss_weights
|
tuple[float, float, float, float, float]
|
Per-attribute loss weights. |
(1.0, 1.0, 1.0, 1.0, 1.0)
|
use_padding_as_vocab
|
bool
|
Whether padding is part of the modeled vocabulary. |
True
|
pos_emb
|
CorrectorPositionEmbedding | str
|
Position embedding mode. |
none
|
transformer_type
|
CorrectorTransformerType | str
|
Corrector transformer variant. |
aggregated
|
corrector_steps
|
int
|
Number of correction passes per selected timestep. |
1
|
corrector_t_list
|
tuple[int, ...]
|
Explicit timesteps where the corrector is applied. |
(10, 20, 30)
|
corrector_mask_mode
|
CorrectorMaskMode | str
|
Strategy for selecting tokens to remask. |
thresh
|
corrector_mask_threshold
|
float
|
Confidence threshold for threshold masking. |
0.7
|
corrector_temperature
|
float
|
Temperature used for corrector resampling. |
1.0
|
use_gumbel_noise
|
bool
|
Whether to perturb confidence logits. |
True
|
gumbel_temperature
|
float
|
Temperature for confidence Gumbel noise. |
1.0
|
time_adaptive_temperature
|
bool
|
Whether to scale noise by timestep ratio. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a supplied dataset, shape, or option is unsupported. |
Examples:
>>> cfg = LayoutCorrectorConfig(dataset_name="publaynet", vocab_size=100)
>>> cfg.max_token_length
125
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
LayoutCorrectorModel ¶
Bases: ModelMixin, ConfigMixin
Diffusers-compatible Layout-Corrector confidence model.
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 | |
__init__ ¶
__init__(
*,
dataset_name: str,
vocab_size: int,
id2label: dict[int | str, str] | None = None,
max_seq_length: int = 25,
num_attributes_per_element: int = 5,
hidden_size: int = 464,
num_attention_heads: int = 8,
num_hidden_layers: int = 4,
intermediate_size: int = 1856,
dropout: float = 0.0,
timestep_type: TimestepEmbeddingType
| str
| None = "adalayernorm",
num_timesteps: int = 100,
recon_type: CorrectorReconType
| str = CorrectorReconType.x_t_minus_1,
target: CorrectorTarget
| str = CorrectorTarget.recon_acc,
attr_loss_weights: tuple[float, ...] = (
1.0,
1.0,
1.0,
1.0,
1.0,
),
use_padding_as_vocab: bool = True,
pos_emb: CorrectorPositionEmbedding
| str = CorrectorPositionEmbedding.none,
transformer_type: CorrectorTransformerType
| str = CorrectorTransformerType.aggregated,
corrector_steps: int = 1,
corrector_t_list: tuple[int, ...] = (10, 20, 30),
corrector_mask_mode: CorrectorMaskMode
| str = CorrectorMaskMode.thresh,
corrector_mask_threshold: float = 0.7,
corrector_temperature: float = 1.0,
use_gumbel_noise: bool = True,
gumbel_temperature: float = 1.0,
time_adaptive_temperature: bool = False,
) -> None
Initialize a Layout-Corrector model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Dataset key or alias used for labels. |
required |
vocab_size
|
int
|
LayoutDM vocabulary size. |
required |
id2label
|
dict[int | str, str] | None
|
Optional class-id mapping. |
None
|
max_seq_length
|
int
|
Maximum number of elements. |
25
|
num_attributes_per_element
|
int
|
Number of token attributes per element. |
5
|
hidden_size
|
int
|
Transformer hidden dimension. |
464
|
num_attention_heads
|
int
|
Number of attention heads. |
8
|
num_hidden_layers
|
int
|
Number of transformer layers. |
4
|
intermediate_size
|
int
|
Feed-forward hidden dimension. |
1856
|
dropout
|
float
|
Dropout probability. |
0.0
|
timestep_type
|
TimestepEmbeddingType | str | None
|
Timestep conditioning type. |
'adalayernorm'
|
num_timesteps
|
int
|
Number of diffusion timesteps. |
100
|
recon_type
|
CorrectorReconType | str
|
Reconstruction target. |
x_t_minus_1
|
target
|
CorrectorTarget | str
|
Confidence target type. |
recon_acc
|
attr_loss_weights
|
tuple[float, ...]
|
Per-attribute loss weights. |
(1.0, 1.0, 1.0, 1.0, 1.0)
|
use_padding_as_vocab
|
bool
|
Whether padding is modeled as a vocabulary token. |
True
|
pos_emb
|
CorrectorPositionEmbedding | str
|
Position embedding mode. |
none
|
transformer_type
|
CorrectorTransformerType | str
|
Corrector transformer type. |
aggregated
|
corrector_steps
|
int
|
Number of correction passes. |
1
|
corrector_t_list
|
tuple[int, ...]
|
Explicit correction timesteps. |
(10, 20, 30)
|
corrector_mask_mode
|
CorrectorMaskMode | str
|
Token remasking mode. |
thresh
|
corrector_mask_threshold
|
float
|
Threshold for confidence remasking. |
0.7
|
corrector_temperature
|
float
|
Corrector sampling temperature. |
1.0
|
use_gumbel_noise
|
bool
|
Whether confidence logits receive Gumbel noise. |
True
|
gumbel_temperature
|
float
|
Confidence-noise temperature. |
1.0
|
time_adaptive_temperature
|
bool
|
Whether to scale noise by timestep ratio. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If reconstruction, target, or transformer options are unsupported. |
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 | |
initialize_weights ¶
initialize_weights() -> None
Apply the released training initialization on the active device.
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
317 318 319 | |
forward ¶
forward(
input_ids: Int[Tensor, "batch tokens"],
timesteps: Int[Tensor, "batch"],
padding_mask: Bool[Tensor, "batch tokens"]
| None = None,
) -> LayoutCorrectorOutput
Run the corrector model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Int[Tensor, 'batch tokens']
|
Flattened token ids. |
required |
timesteps
|
Int[Tensor, 'batch']
|
Diffusion timestep tensor. |
required |
padding_mask
|
Bool[Tensor, 'batch tokens'] | None
|
Optional padding mask. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutCorrectorOutput
|
|
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 | |
calc_confidence_score ¶
calc_confidence_score(
input_ids: Int[Tensor, "batch tokens"],
timesteps: Int[Tensor, "batch"],
padding_mask: Bool[Tensor, "batch tokens"]
| None = None,
) -> Float[torch.Tensor, "batch tokens"]
Return confidence logits for token remasking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Int[Tensor, 'batch tokens']
|
Flattened token ids. |
required |
timesteps
|
Int[Tensor, 'batch']
|
Diffusion timestep tensor. |
required |
padding_mask
|
Bool[Tensor, 'batch tokens'] | None
|
Optional padding mask. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch tokens']
|
Confidence logits shaped |
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
LayoutCorrectorOutput
dataclass
¶
Bases: BaseOutput
Output container for Layout-Corrector confidence logits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Float[Tensor, 'batch tokens']
|
Token confidence logits shaped |
required |
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
43 44 45 46 47 48 49 50 51 | |
LayoutCorrectorPipeline ¶
Bases: DiffusionPipeline
Diffusers pipeline that applies Layout-Corrector during LayoutDM sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout_dm
|
LayoutDMPipeline
|
Base LayoutDM pipeline. |
required |
corrector
|
LayoutCorrectorModel
|
Corrector model used to score and remask tokens. |
required |
processor
|
LayoutDMProcessor | None
|
Optional processor for conditional layout inputs. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Pipeline construction does not raise directly. |
Examples:
>>> LayoutCorrectorPipeline.from_pretrained
<bound method...
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
__init__ ¶
__init__(
layout_dm: LayoutDMPipeline,
corrector: LayoutCorrectorModel,
processor: LayoutDMProcessor | None = None,
) -> None
Initialize the composite pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout_dm
|
LayoutDMPipeline
|
Base LayoutDM pipeline. |
required |
corrector
|
LayoutCorrectorModel
|
Confidence model used to remask low-confidence tokens. |
required |
processor
|
LayoutDMProcessor | None
|
Optional processor for conditional inputs. |
None
|
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
to ¶
to(
*args: device | str | dtype | None,
dtype: dtype | None = None,
device: device | str | None = None,
silence_dtype_warnings: bool = False,
) -> Self
Move the nested LayoutDM pipeline and the corrector together.
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.unconditional,
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| list[ArrayLikeInput]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| list[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| list[ArrayLikeInput]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
sampling: SamplingMode | str = SamplingMode.random,
temperature: float = 1.0,
top_k: int = 5,
top_p: float = 0.9,
corrector_steps: int | None = None,
corrector_t_list: Sequence[int] | None = None,
corrector_start: int = -1,
corrector_end: int = -1,
corrector_mask_mode: CorrectorMaskMode
| str
| None = None,
corrector_mask_threshold: float | None = None,
corrector_temperature: float | None = None,
use_gumbel_noise: bool | None = None,
gumbel_temperature: float | None = None,
time_adaptive_temperature: bool | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "batch elements 4"]
| Int[torch.Tensor, "batch elements"]
| Bool[torch.Tensor, "batch elements"]
| Int[torch.Tensor, "batch tokens"]
| Float[torch.Tensor, "steps batch tokens"]
| list[Int[torch.Tensor, "batch tokens"]]
| dict[int, str]
| dict[str, str]
| None,
]
)
Generate layouts with optional Layout-Corrector guidance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts to sample for unconditional generation. |
1
|
seed
|
int | None
|
Optional seed used when |
None
|
generator
|
Generator | None
|
Optional PyTorch generator. |
None
|
condition_type
|
ConditionType | str
|
Condition mode such as |
unconditional
|
labels
|
Int[Tensor, 'batch elements'] | Int[ndarray, 'batch elements'] | list[ArrayLikeInput] | None
|
Optional class ids for conditional generation. |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | Float[ndarray, 'batch elements 4'] | list[ArrayLikeInput] | None
|
Optional boxes for conditional generation. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Bool[ndarray, 'batch elements'] | list[ArrayLikeInput] | None
|
Optional element mask for conditional generation. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved for future element-count conditioning. |
None
|
box_format
|
BoxFormat | str
|
Coordinate format for conditional boxes. |
xywh
|
normalized
|
bool
|
Whether conditional boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas used when |
None
|
num_inference_steps
|
int | None
|
Optional inference timestep count. |
None
|
sampling
|
SamplingMode | str
|
Base LayoutDM sampling strategy. |
random
|
temperature
|
float
|
Base sampling temperature. |
1.0
|
top_k
|
int
|
Top-k cutoff for top-k sampling. |
5
|
top_p
|
float
|
Nucleus cutoff for top-p sampling. |
0.9
|
corrector_steps
|
int | None
|
Optional override for correction passes. |
None
|
corrector_t_list
|
Sequence[int] | None
|
Optional explicit correction timesteps. |
None
|
corrector_start
|
int
|
Range start for correction when no list is supplied. |
-1
|
corrector_end
|
int
|
Range end for correction when no list is supplied. |
-1
|
corrector_mask_mode
|
CorrectorMaskMode | str | None
|
Optional override for remasking mode. |
None
|
corrector_mask_threshold
|
float | None
|
Optional threshold override. |
None
|
corrector_temperature
|
float | None
|
Optional confidence temperature override. |
None
|
use_gumbel_noise
|
bool | None
|
Optional confidence-noise override. |
None
|
gumbel_temperature
|
float | None
|
Optional confidence-noise temperature override. |
None
|
time_adaptive_temperature
|
bool | None
|
Optional adaptive-noise override. |
None
|
output_type
|
OutputType | str
|
|
dataclass
|
return_intermediates
|
bool
|
Whether to include scores and trajectory. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, 'batch elements 4'] | Int[Tensor, 'batch elements'] | Bool[Tensor, 'batch elements'] | Int[Tensor, 'batch tokens'] | Float[Tensor, 'steps batch tokens'] | list[Int[Tensor, 'batch tokens']] | dict[int, str] | dict[str, str] | None]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If conditional generation is missing |
Examples:
>>> LayoutCorrectorPipeline.__call__
<function...
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | Path,
*,
safe_serialization: bool = True,
) -> None
Save the nested LayoutDM pipeline and corrector model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Destination directory. |
required |
safe_serialization
|
bool
|
Whether to save weights as safetensors. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
OSError
|
If files cannot be written. |
Examples:
>>> LayoutCorrectorPipeline.save_pretrained
<function...
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
*,
processor: LayoutDMProcessor | None = None,
) -> "LayoutCorrectorPipeline"
Load a Layout-Corrector pipeline from a saved directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | Path
|
Directory containing |
required |
processor
|
LayoutDMProcessor | None
|
Optional processor override. |
None
|
Returns:
| Type | Description |
|---|---|
'LayoutCorrectorPipeline'
|
Loaded |
Raises:
| Type | Description |
|---|---|
OSError
|
If nested component files are missing. |
Examples:
>>> LayoutCorrectorPipeline.from_pretrained
<bound method...
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
CorrectorMaskMode ¶
Bases: StrEnum
Supported token remasking modes for Layout-Corrector.
Source code in models/layout-corrector/src/layout_corrector/sampling.py
20 21 22 23 24 | |
LayoutCorrectorSamplingConfig
dataclass
¶
Sampling options for Layout-Corrector-guided diffusion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling
|
SamplingMode | str
|
Base LayoutDM sampling strategy. |
random
|
temperature
|
float
|
Base sampling temperature. |
1.0
|
top_k
|
int
|
Top-k cutoff for top-k sampling. |
5
|
top_p
|
float
|
Nucleus cutoff for top-p sampling. |
0.9
|
num_inference_steps
|
int | None
|
Optional inference timestep count. |
None
|
corrector_steps
|
int
|
Number of correction passes per selected timestep. |
1
|
corrector_t_list
|
tuple[int, ...]
|
Explicit timesteps where the corrector is applied. |
(10, 20, 30)
|
corrector_start
|
int
|
Start timestep for range-based correction. |
-1
|
corrector_end
|
int
|
End timestep for range-based correction. |
-1
|
corrector_mask_mode
|
CorrectorMaskMode | str
|
Strategy for selecting tokens to remask. |
thresh
|
corrector_mask_threshold
|
float
|
Confidence threshold for threshold masking. |
0.7
|
corrector_temperature
|
float
|
Temperature used for confidence masking. |
1.0
|
use_gumbel_noise
|
bool
|
Whether to perturb confidence logits. |
True
|
gumbel_temperature
|
float
|
Temperature for confidence Gumbel noise. |
1.0
|
time_adaptive_temperature
|
bool
|
Whether to scale noise by timestep ratio. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Construction does not raise directly. |
Examples:
>>> LayoutCorrectorSamplingConfig(corrector_t_list=(10,)).corrector_t_list
(10,)
Source code in models/layout-corrector/src/layout_corrector/sampling.py
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 | |
__post_init__ ¶
__post_init__() -> None
Normalize public string modes to enum values.
Source code in models/layout-corrector/src/layout_corrector/sampling.py
86 87 88 89 90 91 | |
configuration_layout_corrector ¶
Configuration objects for Layout-Corrector models.
CorrectorReconType ¶
Bases: StrEnum
Supported Layout-Corrector reconstruction targets.
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
21 22 23 24 25 | |
CorrectorTarget ¶
Bases: StrEnum
Supported Layout-Corrector confidence targets.
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
28 29 30 31 32 | |
CorrectorPositionEmbedding ¶
Bases: StrEnum
Supported original position-embedding modes.
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
35 36 37 38 39 40 41 42 | |
CorrectorTransformerType ¶
Bases: StrEnum
Supported corrector transformer variants.
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
45 46 47 48 | |
LayoutCorrectorConfig ¶
Bases: ConfigMixin
Configuration for the Layout-Corrector transformer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias used for labels. |
required |
vocab_size
|
int
|
LayoutDM vocabulary size expected by the corrector. |
required |
id2label
|
dict[int | str, str] | None
|
Optional class-id mapping. When omitted, the shared registry is used. |
None
|
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
num_attributes_per_element
|
int
|
Number of token attributes per element. |
5
|
hidden_size
|
int
|
Transformer hidden dimension. |
464
|
num_attention_heads
|
int
|
Number of attention heads. |
8
|
num_hidden_layers
|
int
|
Number of transformer layers. |
4
|
intermediate_size
|
int
|
Feed-forward hidden dimension. |
1856
|
dropout
|
float
|
Dropout probability. |
0.0
|
timestep_type
|
str | None
|
Timestep conditioning type. |
'adalayernorm'
|
num_timesteps
|
int
|
Number of diffusion training timesteps. |
100
|
recon_type
|
CorrectorReconType | str
|
Reconstruction target used by the corrector. |
x_t_minus_1
|
target
|
CorrectorTarget | str
|
Confidence target type. |
recon_acc
|
attr_loss_weights
|
tuple[float, float, float, float, float]
|
Per-attribute loss weights. |
(1.0, 1.0, 1.0, 1.0, 1.0)
|
use_padding_as_vocab
|
bool
|
Whether padding is part of the modeled vocabulary. |
True
|
pos_emb
|
CorrectorPositionEmbedding | str
|
Position embedding mode from the original implementation. |
none
|
transformer_type
|
CorrectorTransformerType | str
|
Corrector transformer variant. |
aggregated
|
corrector_steps
|
int
|
Number of correction passes per selected timestep. |
1
|
corrector_t_list
|
tuple[int, ...]
|
Explicit timesteps where the corrector is applied. |
(10, 20, 30)
|
corrector_mask_mode
|
CorrectorMaskMode | str
|
Strategy for selecting tokens to remask. |
thresh
|
corrector_mask_threshold
|
float
|
Confidence threshold for threshold masking. |
0.7
|
corrector_temperature
|
float
|
Temperature used for corrector resampling. |
1.0
|
use_gumbel_noise
|
bool
|
Whether to perturb confidence logits. |
True
|
gumbel_temperature
|
float
|
Temperature for confidence Gumbel noise. |
1.0
|
time_adaptive_temperature
|
bool
|
Whether to scale noise by timestep ratio. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a supplied dataset, shape, or option is unsupported. |
Examples:
>>> cfg = LayoutCorrectorConfig(dataset_name="publaynet", vocab_size=100)
>>> cfg.max_token_length
125
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
max_token_length
property
¶
max_token_length: int
Return the flattened token length for one layout sequence.
Returns:
| Type | Description |
|---|---|
int
|
Maximum token count after flattening element attributes. |
Examples:
>>> LayoutCorrectorConfig(dataset_name="publaynet", vocab_size=100).max_token_length
125
__init__ ¶
__init__(
*,
dataset_name: DatasetName | str,
vocab_size: int,
id2label: dict[int | str, str] | None = None,
max_seq_length: int = 25,
num_attributes_per_element: int = 5,
hidden_size: int = 464,
num_attention_heads: int = 8,
num_hidden_layers: int = 4,
intermediate_size: int = 1856,
dropout: float = 0.0,
timestep_type: str | None = "adalayernorm",
num_timesteps: int = 100,
recon_type: CorrectorReconType
| str = CorrectorReconType.x_t_minus_1,
target: CorrectorTarget
| str = CorrectorTarget.recon_acc,
attr_loss_weights: tuple[
float, float, float, float, float
] = (1.0, 1.0, 1.0, 1.0, 1.0),
use_padding_as_vocab: bool = True,
pos_emb: CorrectorPositionEmbedding
| str = CorrectorPositionEmbedding.none,
transformer_type: CorrectorTransformerType
| str = CorrectorTransformerType.aggregated,
corrector_steps: int = 1,
corrector_t_list: tuple[int, ...] = (10, 20, 30),
corrector_mask_mode: CorrectorMaskMode
| str = CorrectorMaskMode.thresh,
corrector_mask_threshold: float = 0.7,
corrector_temperature: float = 1.0,
use_gumbel_noise: bool = True,
gumbel_temperature: float = 1.0,
time_adaptive_temperature: bool = False,
) -> None
Initialize a Layout-Corrector config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Dataset key or alias used for labels. |
required |
vocab_size
|
int
|
LayoutDM vocabulary size expected by the corrector. |
required |
id2label
|
dict[int | str, str] | None
|
Optional class-id mapping. |
None
|
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
num_attributes_per_element
|
int
|
Number of token attributes per element. |
5
|
hidden_size
|
int
|
Transformer hidden dimension. |
464
|
num_attention_heads
|
int
|
Number of attention heads. |
8
|
num_hidden_layers
|
int
|
Number of transformer layers. |
4
|
intermediate_size
|
int
|
Feed-forward hidden dimension. |
1856
|
dropout
|
float
|
Dropout probability. |
0.0
|
timestep_type
|
str | None
|
Timestep conditioning type. |
'adalayernorm'
|
num_timesteps
|
int
|
Number of diffusion training timesteps. |
100
|
recon_type
|
CorrectorReconType | str
|
Reconstruction target used by the corrector. |
x_t_minus_1
|
target
|
CorrectorTarget | str
|
Confidence target type. |
recon_acc
|
attr_loss_weights
|
tuple[float, float, float, float, float]
|
Per-attribute loss weights. |
(1.0, 1.0, 1.0, 1.0, 1.0)
|
use_padding_as_vocab
|
bool
|
Whether padding is part of the modeled vocabulary. |
True
|
pos_emb
|
CorrectorPositionEmbedding | str
|
Position embedding mode. |
none
|
transformer_type
|
CorrectorTransformerType | str
|
Corrector transformer variant. |
aggregated
|
corrector_steps
|
int
|
Number of correction passes per selected timestep. |
1
|
corrector_t_list
|
tuple[int, ...]
|
Explicit timesteps where the corrector is applied. |
(10, 20, 30)
|
corrector_mask_mode
|
CorrectorMaskMode | str
|
Strategy for selecting tokens to remask. |
thresh
|
corrector_mask_threshold
|
float
|
Confidence threshold for threshold masking. |
0.7
|
corrector_temperature
|
float
|
Temperature used for corrector resampling. |
1.0
|
use_gumbel_noise
|
bool
|
Whether to perturb confidence logits. |
True
|
gumbel_temperature
|
float
|
Temperature for confidence Gumbel noise. |
1.0
|
time_adaptive_temperature
|
bool
|
Whether to scale noise by timestep ratio. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a supplied dataset, shape, or option is unsupported. |
Examples:
>>> cfg = LayoutCorrectorConfig(dataset_name="publaynet", vocab_size=100)
>>> cfg.max_token_length
125
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
normalize_corrector_core_options ¶
normalize_corrector_core_options(
recon_type: CorrectorReconType | str,
target: CorrectorTarget | str,
transformer_type: CorrectorTransformerType | str,
pos_emb: CorrectorPositionEmbedding | str,
) -> tuple[
CorrectorReconType,
CorrectorTarget,
CorrectorTransformerType,
CorrectorPositionEmbedding,
]
Normalize shared Layout-Corrector enum options.
Source code in models/layout-corrector/src/layout_corrector/configuration_layout_corrector.py
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 | |
conversion ¶
Conversion helpers for original Layout-Corrector checkpoints.
LayoutDMPipelineLike ¶
Bases: Protocol
Nested LayoutDM pipeline surface needed during conversion.
Source code in models/layout-corrector/src/layout_corrector/conversion.py
39 40 41 42 43 | |
CompatibilityKey ¶
Bases: StrEnum
LayoutDM fields that must match the converted corrector config.
Source code in models/layout-corrector/src/layout_corrector/conversion.py
46 47 48 49 50 51 52 | |
OriginalDatasetConfig ¶
Bases: TypedDict
Dataset section of the original Layout-Corrector YAML.
Source code in models/layout-corrector/src/layout_corrector/conversion.py
55 56 57 58 | |
OriginalDataConfig ¶
Bases: TypedDict
Data section of the original Layout-Corrector YAML.
Source code in models/layout-corrector/src/layout_corrector/conversion.py
61 62 63 64 | |
OriginalModelConfig ¶
Bases: TypedDict
Model section of the original Layout-Corrector YAML.
Source code in models/layout-corrector/src/layout_corrector/conversion.py
67 68 69 70 71 72 73 74 75 76 | |
OriginalEncoderLayerConfig ¶
Bases: TypedDict
Backbone encoder-layer section of the original YAML.
Source code in models/layout-corrector/src/layout_corrector/conversion.py
79 80 81 82 83 84 | |
OriginalBackboneConfig ¶
Bases: TypedDict
Backbone section of the original Layout-Corrector YAML.
Source code in models/layout-corrector/src/layout_corrector/conversion.py
87 88 89 90 91 | |
OriginalConfig ¶
Bases: TypedDict
Typed shape for the original Layout-Corrector YAML.
Source code in models/layout-corrector/src/layout_corrector/conversion.py
94 95 96 97 98 99 100 | |
remap_corrector_key ¶
remap_corrector_key(key: str) -> str
Map an original checkpoint key to the converted module key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Original state-dict key. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Key accepted by |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the key does not use an expected original prefix. |
Source code in models/layout-corrector/src/layout_corrector/conversion.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
split_original_corrector_state_dict ¶
split_original_corrector_state_dict(
state_dict: dict[str, Shaped[Tensor, "..."]],
) -> dict[str, Shaped[torch.Tensor, "..."]]
Strip original wrapper prefixes from a corrector state dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dict
|
dict[str, Shaped[Tensor, '...']]
|
Original checkpoint state dictionary. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Converted state dictionary. |
Source code in models/layout-corrector/src/layout_corrector/conversion.py
121 122 123 124 125 126 127 128 129 130 131 132 | |
load_original_corrector_state_dict ¶
load_original_corrector_state_dict(
path: str | Path,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Load and remap an original corrector checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Converted state dictionary. |
Source code in models/layout-corrector/src/layout_corrector/conversion.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
corrector_config_from_original ¶
corrector_config_from_original(
*,
dataset: str,
config_path: str | Path,
state_dict: dict[str, Shaped[Tensor, "..."]],
layout_dm: LayoutDMPipelineLike,
) -> LayoutCorrectorConfig
Build a Layout-Corrector config from original files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str
|
Dataset key or alias. |
required |
config_path
|
str | Path
|
Original |
required |
state_dict
|
dict[str, Shaped[Tensor, '...']]
|
Converted corrector state dictionary. |
required |
layout_dm
|
LayoutDMPipelineLike
|
Nested LayoutDM pipeline used for compatibility checks. |
required |
Returns:
| Type | Description |
|---|---|
LayoutCorrectorConfig
|
Converted Layout-Corrector config. |
Source code in models/layout-corrector/src/layout_corrector/conversion.py
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 | |
build_corrector_from_original ¶
build_corrector_from_original(
*,
dataset: str,
checkpoint_dir: str | Path,
layout_dm: LayoutDMPipelineLike,
) -> LayoutCorrectorModel
Build a LayoutCorrectorModel from an original checkpoint directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str
|
Dataset key or alias. |
required |
checkpoint_dir
|
str | Path
|
Directory containing |
required |
layout_dm
|
LayoutDMPipelineLike
|
Nested LayoutDM pipeline paired with the corrector. |
required |
Returns:
| Type | Description |
|---|---|
LayoutCorrectorModel
|
Loaded and eval-mode corrector model. |
Source code in models/layout-corrector/src/layout_corrector/conversion.py
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 | |
discover_seed_dirs ¶
discover_seed_dirs(job_dir: str | Path) -> list[Path]
Discover corrector seed directories under an original job directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_dir
|
str | Path
|
Seed directory or parent directory containing seed subdirectories. |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
Sorted list of directories containing |
Source code in models/layout-corrector/src/layout_corrector/conversion.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
validate_layout_dm_compatibility ¶
validate_layout_dm_compatibility(
*,
layout_dm: LayoutDMPipelineLike,
corrector_config: LayoutCorrectorConfig,
) -> None
Validate that a corrector config matches its nested LayoutDM pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout_dm
|
LayoutDMPipelineLike
|
Nested LayoutDM pipeline. |
required |
corrector_config
|
LayoutCorrectorConfig
|
Corrector config to compare. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a shared tokenizer or scheduler field differs. |
Source code in models/layout-corrector/src/layout_corrector/conversion.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
model_card ¶
Model-card builders for converted Layout-Corrector checkpoints.
LayoutCorrectorCardDataset ¶
Bases: StrEnum
Canonical datasets used in Layout-Corrector model-card metadata.
Source code in models/layout-corrector/src/layout_corrector/model_card.py
19 20 21 22 23 24 | |
LayoutCorrectorCardValue ¶
Bases: StrEnum
Closed metadata and tag values emitted by Layout-Corrector cards.
Source code in models/layout-corrector/src/layout_corrector/model_card.py
27 28 29 30 31 32 33 34 | |
layout_corrector_model_card ¶
layout_corrector_model_card(
*,
dataset: str,
parity_metrics: Sequence[ParityMetricInput]
| None = None,
) -> ModelCard
Build the Layout-Corrector model card for a converted checkpoint.
Source code in models/layout-corrector/src/layout_corrector/model_card.py
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 | |
modeling_layout_corrector ¶
Layout-Corrector confidence model components.
LayoutCorrectorOutput
dataclass
¶
Bases: BaseOutput
Output container for Layout-Corrector confidence logits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Float[Tensor, 'batch tokens']
|
Token confidence logits shaped |
required |
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
43 44 45 46 47 48 49 50 51 | |
AggregatedCategoricalTransformer ¶
Bases: Module
Aggregated-token transformer used by the original Layout-Corrector model.
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 | |
__init__ ¶
__init__(
*,
vocab_size: int,
max_token_length: int,
hidden_size: int,
num_attention_heads: int,
num_hidden_layers: int,
intermediate_size: int,
dropout: float,
timestep_type: TimestepEmbeddingType | str | None,
pos_emb: CorrectorPositionEmbedding | str,
num_attributes_per_element: int,
num_timesteps: int,
) -> None
Initialize the aggregated categorical transformer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vocab_size
|
int
|
Number of token ids. |
required |
max_token_length
|
int
|
Flattened token sequence length. |
required |
hidden_size
|
int
|
Transformer hidden dimension. |
required |
num_attention_heads
|
int
|
Number of attention heads. |
required |
num_hidden_layers
|
int
|
Number of transformer layers. |
required |
intermediate_size
|
int
|
Feed-forward hidden dimension. |
required |
dropout
|
float
|
Dropout probability. |
required |
timestep_type
|
TimestepEmbeddingType | str | None
|
Timestep conditioning type. |
required |
pos_emb
|
CorrectorPositionEmbedding | str
|
Position embedding mode. |
required |
num_attributes_per_element
|
int
|
Number of attributes per layout element. |
required |
num_timesteps
|
int
|
Diffusion timestep count. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 | |
forward ¶
forward(
input_ids: Int[Tensor, "batch tokens"],
*,
timestep: Int[Tensor, "batch"] | None = None,
src_key_padding_mask: Bool[Tensor, "batch tokens"]
| None = None,
) -> Float[torch.Tensor, "batch tokens 1"]
Predict token confidence logits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Int[Tensor, 'batch tokens']
|
Flattened token ids. |
required |
timestep
|
Int[Tensor, 'batch'] | None
|
Optional diffusion timestep tensor. |
None
|
src_key_padding_mask
|
Bool[Tensor, 'batch tokens'] | None
|
Optional padding mask. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch tokens 1']
|
Confidence logits shaped |
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 | |
LayoutCorrectorModel ¶
Bases: ModelMixin, ConfigMixin
Diffusers-compatible Layout-Corrector confidence model.
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 | |
__init__ ¶
__init__(
*,
dataset_name: str,
vocab_size: int,
id2label: dict[int | str, str] | None = None,
max_seq_length: int = 25,
num_attributes_per_element: int = 5,
hidden_size: int = 464,
num_attention_heads: int = 8,
num_hidden_layers: int = 4,
intermediate_size: int = 1856,
dropout: float = 0.0,
timestep_type: TimestepEmbeddingType
| str
| None = "adalayernorm",
num_timesteps: int = 100,
recon_type: CorrectorReconType
| str = CorrectorReconType.x_t_minus_1,
target: CorrectorTarget
| str = CorrectorTarget.recon_acc,
attr_loss_weights: tuple[float, ...] = (
1.0,
1.0,
1.0,
1.0,
1.0,
),
use_padding_as_vocab: bool = True,
pos_emb: CorrectorPositionEmbedding
| str = CorrectorPositionEmbedding.none,
transformer_type: CorrectorTransformerType
| str = CorrectorTransformerType.aggregated,
corrector_steps: int = 1,
corrector_t_list: tuple[int, ...] = (10, 20, 30),
corrector_mask_mode: CorrectorMaskMode
| str = CorrectorMaskMode.thresh,
corrector_mask_threshold: float = 0.7,
corrector_temperature: float = 1.0,
use_gumbel_noise: bool = True,
gumbel_temperature: float = 1.0,
time_adaptive_temperature: bool = False,
) -> None
Initialize a Layout-Corrector model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Dataset key or alias used for labels. |
required |
vocab_size
|
int
|
LayoutDM vocabulary size. |
required |
id2label
|
dict[int | str, str] | None
|
Optional class-id mapping. |
None
|
max_seq_length
|
int
|
Maximum number of elements. |
25
|
num_attributes_per_element
|
int
|
Number of token attributes per element. |
5
|
hidden_size
|
int
|
Transformer hidden dimension. |
464
|
num_attention_heads
|
int
|
Number of attention heads. |
8
|
num_hidden_layers
|
int
|
Number of transformer layers. |
4
|
intermediate_size
|
int
|
Feed-forward hidden dimension. |
1856
|
dropout
|
float
|
Dropout probability. |
0.0
|
timestep_type
|
TimestepEmbeddingType | str | None
|
Timestep conditioning type. |
'adalayernorm'
|
num_timesteps
|
int
|
Number of diffusion timesteps. |
100
|
recon_type
|
CorrectorReconType | str
|
Reconstruction target. |
x_t_minus_1
|
target
|
CorrectorTarget | str
|
Confidence target type. |
recon_acc
|
attr_loss_weights
|
tuple[float, ...]
|
Per-attribute loss weights. |
(1.0, 1.0, 1.0, 1.0, 1.0)
|
use_padding_as_vocab
|
bool
|
Whether padding is modeled as a vocabulary token. |
True
|
pos_emb
|
CorrectorPositionEmbedding | str
|
Position embedding mode. |
none
|
transformer_type
|
CorrectorTransformerType | str
|
Corrector transformer type. |
aggregated
|
corrector_steps
|
int
|
Number of correction passes. |
1
|
corrector_t_list
|
tuple[int, ...]
|
Explicit correction timesteps. |
(10, 20, 30)
|
corrector_mask_mode
|
CorrectorMaskMode | str
|
Token remasking mode. |
thresh
|
corrector_mask_threshold
|
float
|
Threshold for confidence remasking. |
0.7
|
corrector_temperature
|
float
|
Corrector sampling temperature. |
1.0
|
use_gumbel_noise
|
bool
|
Whether confidence logits receive Gumbel noise. |
True
|
gumbel_temperature
|
float
|
Confidence-noise temperature. |
1.0
|
time_adaptive_temperature
|
bool
|
Whether to scale noise by timestep ratio. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If reconstruction, target, or transformer options are unsupported. |
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 | |
initialize_weights ¶
initialize_weights() -> None
Apply the released training initialization on the active device.
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
317 318 319 | |
forward ¶
forward(
input_ids: Int[Tensor, "batch tokens"],
timesteps: Int[Tensor, "batch"],
padding_mask: Bool[Tensor, "batch tokens"]
| None = None,
) -> LayoutCorrectorOutput
Run the corrector model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Int[Tensor, 'batch tokens']
|
Flattened token ids. |
required |
timesteps
|
Int[Tensor, 'batch']
|
Diffusion timestep tensor. |
required |
padding_mask
|
Bool[Tensor, 'batch tokens'] | None
|
Optional padding mask. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutCorrectorOutput
|
|
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 | |
calc_confidence_score ¶
calc_confidence_score(
input_ids: Int[Tensor, "batch tokens"],
timesteps: Int[Tensor, "batch"],
padding_mask: Bool[Tensor, "batch tokens"]
| None = None,
) -> Float[torch.Tensor, "batch tokens"]
Return confidence logits for token remasking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Int[Tensor, 'batch tokens']
|
Flattened token ids. |
required |
timesteps
|
Int[Tensor, 'batch']
|
Diffusion timestep tensor. |
required |
padding_mask
|
Bool[Tensor, 'batch tokens'] | None
|
Optional padding mask. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch tokens']
|
Confidence logits shaped |
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
pipeline_layout_corrector ¶
Diffusers pipeline wrapper for Layout-Corrector guided generation.
OutputType ¶
Bases: StrEnum
Supported Layout-Corrector pipeline output formats.
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
40 41 42 43 44 | |
LayoutCorrectorPipeline ¶
Bases: DiffusionPipeline
Diffusers pipeline that applies Layout-Corrector during LayoutDM sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout_dm
|
LayoutDMPipeline
|
Base LayoutDM pipeline. |
required |
corrector
|
LayoutCorrectorModel
|
Corrector model used to score and remask tokens. |
required |
processor
|
LayoutDMProcessor | None
|
Optional processor for conditional layout inputs. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Pipeline construction does not raise directly. |
Examples:
>>> LayoutCorrectorPipeline.from_pretrained
<bound method...
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
__init__ ¶
__init__(
layout_dm: LayoutDMPipeline,
corrector: LayoutCorrectorModel,
processor: LayoutDMProcessor | None = None,
) -> None
Initialize the composite pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout_dm
|
LayoutDMPipeline
|
Base LayoutDM pipeline. |
required |
corrector
|
LayoutCorrectorModel
|
Confidence model used to remask low-confidence tokens. |
required |
processor
|
LayoutDMProcessor | None
|
Optional processor for conditional inputs. |
None
|
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
to ¶
to(
*args: device | str | dtype | None,
dtype: dtype | None = None,
device: device | str | None = None,
silence_dtype_warnings: bool = False,
) -> Self
Move the nested LayoutDM pipeline and the corrector together.
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.unconditional,
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| list[ArrayLikeInput]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| list[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| list[ArrayLikeInput]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
sampling: SamplingMode | str = SamplingMode.random,
temperature: float = 1.0,
top_k: int = 5,
top_p: float = 0.9,
corrector_steps: int | None = None,
corrector_t_list: Sequence[int] | None = None,
corrector_start: int = -1,
corrector_end: int = -1,
corrector_mask_mode: CorrectorMaskMode
| str
| None = None,
corrector_mask_threshold: float | None = None,
corrector_temperature: float | None = None,
use_gumbel_noise: bool | None = None,
gumbel_temperature: float | None = None,
time_adaptive_temperature: bool | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "batch elements 4"]
| Int[torch.Tensor, "batch elements"]
| Bool[torch.Tensor, "batch elements"]
| Int[torch.Tensor, "batch tokens"]
| Float[torch.Tensor, "steps batch tokens"]
| list[Int[torch.Tensor, "batch tokens"]]
| dict[int, str]
| dict[str, str]
| None,
]
)
Generate layouts with optional Layout-Corrector guidance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts to sample for unconditional generation. |
1
|
seed
|
int | None
|
Optional seed used when |
None
|
generator
|
Generator | None
|
Optional PyTorch generator. |
None
|
condition_type
|
ConditionType | str
|
Condition mode such as |
unconditional
|
labels
|
Int[Tensor, 'batch elements'] | Int[ndarray, 'batch elements'] | list[ArrayLikeInput] | None
|
Optional class ids for conditional generation. |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | Float[ndarray, 'batch elements 4'] | list[ArrayLikeInput] | None
|
Optional boxes for conditional generation. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Bool[ndarray, 'batch elements'] | list[ArrayLikeInput] | None
|
Optional element mask for conditional generation. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Reserved for future element-count conditioning. |
None
|
box_format
|
BoxFormat | str
|
Coordinate format for conditional boxes. |
xywh
|
normalized
|
bool
|
Whether conditional boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas used when |
None
|
num_inference_steps
|
int | None
|
Optional inference timestep count. |
None
|
sampling
|
SamplingMode | str
|
Base LayoutDM sampling strategy. |
random
|
temperature
|
float
|
Base sampling temperature. |
1.0
|
top_k
|
int
|
Top-k cutoff for top-k sampling. |
5
|
top_p
|
float
|
Nucleus cutoff for top-p sampling. |
0.9
|
corrector_steps
|
int | None
|
Optional override for correction passes. |
None
|
corrector_t_list
|
Sequence[int] | None
|
Optional explicit correction timesteps. |
None
|
corrector_start
|
int
|
Range start for correction when no list is supplied. |
-1
|
corrector_end
|
int
|
Range end for correction when no list is supplied. |
-1
|
corrector_mask_mode
|
CorrectorMaskMode | str | None
|
Optional override for remasking mode. |
None
|
corrector_mask_threshold
|
float | None
|
Optional threshold override. |
None
|
corrector_temperature
|
float | None
|
Optional confidence temperature override. |
None
|
use_gumbel_noise
|
bool | None
|
Optional confidence-noise override. |
None
|
gumbel_temperature
|
float | None
|
Optional confidence-noise temperature override. |
None
|
time_adaptive_temperature
|
bool | None
|
Optional adaptive-noise override. |
None
|
output_type
|
OutputType | str
|
|
dataclass
|
return_intermediates
|
bool
|
Whether to include scores and trajectory. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, 'batch elements 4'] | Int[Tensor, 'batch elements'] | Bool[Tensor, 'batch elements'] | Int[Tensor, 'batch tokens'] | Float[Tensor, 'steps batch tokens'] | list[Int[Tensor, 'batch tokens']] | dict[int, str] | dict[str, str] | None]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If conditional generation is missing |
Examples:
>>> LayoutCorrectorPipeline.__call__
<function...
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | Path,
*,
safe_serialization: bool = True,
) -> None
Save the nested LayoutDM pipeline and corrector model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Destination directory. |
required |
safe_serialization
|
bool
|
Whether to save weights as safetensors. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
OSError
|
If files cannot be written. |
Examples:
>>> LayoutCorrectorPipeline.save_pretrained
<function...
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
*,
processor: LayoutDMProcessor | None = None,
) -> "LayoutCorrectorPipeline"
Load a Layout-Corrector pipeline from a saved directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | Path
|
Directory containing |
required |
processor
|
LayoutDMProcessor | None
|
Optional processor override. |
None
|
Returns:
| Type | Description |
|---|---|
'LayoutCorrectorPipeline'
|
Loaded |
Raises:
| Type | Description |
|---|---|
OSError
|
If nested component files are missing. |
Examples:
>>> LayoutCorrectorPipeline.from_pretrained
<bound method...
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
normalize_output_type ¶
normalize_output_type(
output_type: OutputType | str,
) -> OutputType
Normalize a public output format string to OutputType.
Source code in models/layout-corrector/src/layout_corrector/pipeline_layout_corrector.py
47 48 49 50 51 52 53 54 | |
sampling ¶
Sampling helpers for Layout-Corrector guided generation.
CorrectorMaskMode ¶
Bases: StrEnum
Supported token remasking modes for Layout-Corrector.
Source code in models/layout-corrector/src/layout_corrector/sampling.py
20 21 22 23 24 | |
LayoutCorrectorSamplingConfig
dataclass
¶
Sampling options for Layout-Corrector-guided diffusion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling
|
SamplingMode | str
|
Base LayoutDM sampling strategy. |
random
|
temperature
|
float
|
Base sampling temperature. |
1.0
|
top_k
|
int
|
Top-k cutoff for top-k sampling. |
5
|
top_p
|
float
|
Nucleus cutoff for top-p sampling. |
0.9
|
num_inference_steps
|
int | None
|
Optional inference timestep count. |
None
|
corrector_steps
|
int
|
Number of correction passes per selected timestep. |
1
|
corrector_t_list
|
tuple[int, ...]
|
Explicit timesteps where the corrector is applied. |
(10, 20, 30)
|
corrector_start
|
int
|
Start timestep for range-based correction. |
-1
|
corrector_end
|
int
|
End timestep for range-based correction. |
-1
|
corrector_mask_mode
|
CorrectorMaskMode | str
|
Strategy for selecting tokens to remask. |
thresh
|
corrector_mask_threshold
|
float
|
Confidence threshold for threshold masking. |
0.7
|
corrector_temperature
|
float
|
Temperature used for confidence masking. |
1.0
|
use_gumbel_noise
|
bool
|
Whether to perturb confidence logits. |
True
|
gumbel_temperature
|
float
|
Temperature for confidence Gumbel noise. |
1.0
|
time_adaptive_temperature
|
bool
|
Whether to scale noise by timestep ratio. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Construction does not raise directly. |
Examples:
>>> LayoutCorrectorSamplingConfig(corrector_t_list=(10,)).corrector_t_list
(10,)
Source code in models/layout-corrector/src/layout_corrector/sampling.py
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 | |
__post_init__ ¶
__post_init__() -> None
Normalize public string modes to enum values.
Source code in models/layout-corrector/src/layout_corrector/sampling.py
86 87 88 89 90 91 | |
normalize_corrector_mask_mode ¶
normalize_corrector_mask_mode(
corrector_mask_mode: CorrectorMaskMode | str,
) -> CorrectorMaskMode
Normalize a public remasking mode to CorrectorMaskMode.
Source code in models/layout-corrector/src/layout_corrector/sampling.py
27 28 29 30 31 32 33 34 35 36 37 38 | |
should_apply_corrector ¶
should_apply_corrector(
diffusion_index: int,
config: LayoutCorrectorSamplingConfig,
) -> bool
Return whether the corrector should run at a diffusion timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diffusion_index
|
int
|
Current diffusion timestep. |
required |
config
|
LayoutCorrectorSamplingConfig
|
Corrector sampling options. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
This function does not raise. |
Examples:
>>> should_apply_corrector(10, LayoutCorrectorSamplingConfig(corrector_t_list=(10,)))
True
Source code in models/layout-corrector/src/layout_corrector/sampling.py
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 | |
add_confidence_gumbel_noise ¶
add_confidence_gumbel_noise(
confidence_logits: Float[Tensor, "batch tokens"],
*,
timestep: Int[Tensor, "batch"],
mask_ratio: float,
temperature: float,
time_adaptive_temperature: bool,
generator: Generator | None = None,
) -> Float[torch.Tensor, "batch tokens"]
Add Gumbel noise to confidence logits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confidence_logits
|
Float[Tensor, 'batch tokens']
|
Rank-2 confidence logits. |
required |
timestep
|
Int[Tensor, 'batch']
|
Current timestep tensor. |
required |
mask_ratio
|
float
|
Fraction of tokens still masked. |
required |
temperature
|
float
|
Base noise temperature. |
required |
time_adaptive_temperature
|
bool
|
Whether to scale temperature by |
required |
generator
|
Generator | None
|
Optional PyTorch generator for reproducible noise. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch tokens']
|
Confidence logits after noise injection. |
Raises:
| Type | Description |
|---|---|
ValueError
|
This function does not raise directly. |
Examples:
>>> import torch
>>> logits = torch.zeros(1, 2)
>>> add_confidence_gumbel_noise(
... logits,
... timestep=torch.tensor([1]),
... mask_ratio=0.5,
... temperature=1.0,
... time_adaptive_temperature=False,
... generator=torch.Generator().manual_seed(0),
... ).shape
torch.Size([1, 2])
Source code in models/layout-corrector/src/layout_corrector/sampling.py
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 | |
select_tokens_to_remask ¶
select_tokens_to_remask(
confidence_logits: Float[Tensor, "batch tokens"],
*,
mask_ratio: float,
mode: CorrectorMaskMode | str,
threshold: float,
temperature: float = 1.0,
) -> Bool[torch.Tensor, "batch tokens"]
Select low-confidence tokens that should be masked again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confidence_logits
|
Float[Tensor, 'batch tokens']
|
Rank-2 confidence logits shaped |
required |
mask_ratio
|
float
|
Ratio used to choose top-k remasking count. |
required |
mode
|
CorrectorMaskMode | str
|
Selection mode, either |
required |
threshold
|
float
|
Sigmoid confidence threshold for |
required |
temperature
|
float
|
Temperature applied before thresholding. |
1.0
|
Returns:
| Type | Description |
|---|---|
Bool[Tensor, 'batch tokens']
|
Boolean mask with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If logits are not rank-2 or |
Examples:
>>> import torch
>>> select_tokens_to_remask(torch.zeros(1, 2), mask_ratio=0.5, mode="topk", threshold=0.7).shape
torch.Size([1, 2])
Source code in models/layout-corrector/src/layout_corrector/sampling.py
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 | |
training ¶
Training entry points for Layout-Corrector.
LayoutCorrectorDataModule ¶
Bases: LightningDataModule
Construct train, validation, and test loaders from processed LayoutDM data.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
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 | |
__init__ ¶
__init__(
*,
dataset_name: LayoutCorrectorTrainingDatasetName,
config: LayoutDMConfig,
processed_data_dir: str | Path,
batch_size: int = 64,
num_workers: int = 16,
max_seq_length: int = 25,
random_order: bool = True,
pin_memory: bool = True,
) -> None
Initialize a processed LayoutDM data-module configuration.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
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 | |
setup ¶
setup(stage: str | None = None) -> None
Open the requested processed splits.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
train_dataloader ¶
train_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."] | str]
]
Return the LayoutDM-shaped 16-worker training stream.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
93 94 95 96 97 | |
val_dataloader ¶
val_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."] | str]
]
Return the validation stream.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
99 100 101 102 103 | |
test_dataloader ¶
test_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."] | str]
]
Return the test stream.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
105 106 107 108 109 | |
FrozenLayoutDMReference
dataclass
¶
Package-side frozen LayoutDM model, tokenizer, and schedules.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
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 | |
from_checkpoint
classmethod
¶
from_checkpoint(
*,
dataset_name: str,
checkpoint_path: str | Path,
cluster_centers_path: str | Path,
initialization_device: device | str = "cpu",
) -> "FrozenLayoutDMReference"
Load the selected seed-0 checkpoint and preserve its state tensors.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
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 | |
to ¶
to(device: device | str) -> 'FrozenLayoutDMReference'
Move the reference model and its comparison buffers.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
143 144 145 146 147 148 149 | |
sample_time ¶
sample_time(
batch_size: int, *, device: device
) -> tuple[
Int[torch.Tensor, "batch"], Float[torch.Tensor, "batch"]
]
Use the released importance sampler and its frozen loss history.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
151 152 153 154 155 156 157 158 159 160 161 162 163 | |
corrupt ¶
corrupt(
input_ids: Int[Tensor, "batch tokens"],
timesteps: Int[Tensor, "batch"],
) -> tuple[
Int[torch.Tensor, "batch tokens"],
Float[torch.Tensor, "batch vocab tokens"],
]
Apply constrained LayoutDM corruption with reference random sampling.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
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 | |
prediction_log_probs ¶
prediction_log_probs(
log_xt: Float[Tensor, "batch vocab tokens"],
timesteps: Int[Tensor, "batch"],
) -> Float[torch.Tensor, "batch vocab tokens"]
Predict clean-token probabilities with the frozen denoiser.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
199 200 201 202 203 204 205 206 | |
reconstruct_previous ¶
reconstruct_previous(
log_x0: Float[Tensor, "batch vocab tokens"],
log_xt: Float[Tensor, "batch vocab tokens"],
timesteps: Int[Tensor, "batch"],
) -> Int[torch.Tensor, "batch tokens"]
Sample the reference x_t-1 reconstruction, excluding MASK.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
config ¶
Configuration types for Layout-Corrector training.
dataset ¶
Processed LayoutDM streams used by Layout-Corrector training.
LayoutCorrectorDataModule ¶
Bases: LightningDataModule
Construct train, validation, and test loaders from processed LayoutDM data.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
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 | |
__init__ ¶
__init__(
*,
dataset_name: LayoutCorrectorTrainingDatasetName,
config: LayoutDMConfig,
processed_data_dir: str | Path,
batch_size: int = 64,
num_workers: int = 16,
max_seq_length: int = 25,
random_order: bool = True,
pin_memory: bool = True,
) -> None
Initialize a processed LayoutDM data-module configuration.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
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 | |
setup ¶
setup(stage: str | None = None) -> None
Open the requested processed splits.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
train_dataloader ¶
train_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."] | str]
]
Return the LayoutDM-shaped 16-worker training stream.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
93 94 95 96 97 | |
val_dataloader ¶
val_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."] | str]
]
Return the validation stream.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
99 100 101 102 103 | |
test_dataloader ¶
test_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."] | str]
]
Return the test stream.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
105 106 107 108 109 | |
first_sample_ids ¶
first_sample_ids(
loader: DataLoader[
dict[str, Shaped[Tensor, "..."] | str]
],
count: int = 8,
) -> list[str]
Return the first sample identifiers without consuming a second stream.
Source code in models/layout-corrector/src/layout_corrector/training/dataset.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
lightning_module ¶
Package-local Layout-Corrector training module.
LayoutCorrectorTrainingModule ¶
Bases: LightningModule
Reproduce the original corrector loop with a frozen LayoutDM model.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 382 383 384 385 | |
__init__ ¶
__init__(
*,
config: LayoutCorrectorConfig,
layout_dm_checkpoint_path: str | Path,
cluster_centers_path: str | Path,
learning_rate: float = 0.0005,
weight_decay: float = 0.1,
betas: tuple[float, float] = (0.9, 0.98),
gradient_clip_norm: float = 1.0,
scheduler: LayoutCorrectorTrainingScheduler
| None = "reduce_on_plateau",
scheduler_factor: float = 0.5,
scheduler_patience: int = 2,
scheduler_threshold: float = 0.01,
) -> None
Initialize the corrector and its immutable LayoutDM reference.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
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 | |
on_train_epoch_start ¶
on_train_epoch_start() -> None
Keep the frozen LayoutDM reference in evaluation mode.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
117 118 119 | |
optim_groups ¶
optim_groups() -> list[
dict[str, Iterable[nn.Parameter] | float]
]
Match the reference Linear/LayerNorm/Embedding decay partition.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
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 | |
configure_optimizers ¶
configure_optimizers() -> OptimizerLRScheduler
Return AdamW and the reference epoch-level plateau scheduler.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
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 | |
configure_gradient_clipping ¶
configure_gradient_clipping(
optimizer: Optimizer,
gradient_clip_val: float | None = None,
gradient_clip_algorithm: str | None = None,
) -> None
Clip in model registration order, matching the original loop.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
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 | |
preprocess ¶
preprocess(
batch: dict[str, Shaped[Tensor, "..."] | str],
) -> dict[str, Shaped[torch.Tensor, "..."]]
Build the corrector's corruption and reconstruction targets.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
training_step ¶
training_step(
batch: dict[str, Shaped[Tensor, "..."] | str],
batch_idx: int,
) -> Float[torch.Tensor, ""]
Run one reference-order corrector update.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
343 344 345 346 347 348 349 350 351 | |
validation_step ¶
validation_step(
batch: dict[str, Shaped[Tensor, "..."] | str],
batch_idx: int,
) -> Float[torch.Tensor, ""]
Evaluate one batch before the epoch-level scheduler update.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
353 354 355 356 357 358 359 360 361 | |
on_validation_epoch_start ¶
on_validation_epoch_start() -> None
Reset the per-batch values used by the reference-style reduction.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
363 364 365 | |
on_validation_epoch_end ¶
on_validation_epoch_end() -> None
Log the unweighted mean of validation-batch losses.
Source code in models/layout-corrector/src/layout_corrector/training/lightning_module.py
381 382 383 384 385 | |
parity ¶
Shared parity helpers for the Layout-Corrector training adapter.
ProductionTraceCallback ¶
Bases: Callback
Record the configured Lightning training path for parity evidence.
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
__init__ ¶
__init__(
*,
trace_path: str,
final_state_path: str,
trace_seed: int,
) -> None
Initialize paths and buffers for one production training run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace_path
|
str
|
JSON output path for the per-step trace. |
required |
final_state_path
|
str
|
Output path for the final model state. |
required |
trace_seed
|
int
|
Seed recorded for the production training process. |
required |
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
on_fit_start ¶
on_fit_start(
trainer: Trainer, pl_module: LightningModule
) -> None
Record the production RNG state before the loader is iterated.
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
155 156 157 158 159 160 | |
on_train_batch_start ¶
on_train_batch_start(
trainer: Trainer,
pl_module: LightningModule,
batch: Mapping[str, Shaped[Tensor, "..."] | str],
batch_idx: int,
) -> None
Capture input and RNG digests at the production batch boundary.
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
on_train_batch_end ¶
on_train_batch_end(
trainer: Trainer,
pl_module: LightningModule,
outputs: STEP_OUTPUT,
batch: Mapping[str, Shaped[Tensor, "..."] | str],
batch_idx: int,
) -> None
Record the completed production update and its state digests.
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
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 | |
on_validation_epoch_end ¶
on_validation_epoch_end(
trainer: Trainer, pl_module: LightningModule
) -> None
Capture the validation metric consumed by the plateau scheduler.
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
on_fit_end ¶
on_fit_end(
trainer: Trainer, pl_module: LightningModule
) -> None
Persist the final state and production wiring metadata.
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
build_layout_corrector_step_trace ¶
build_layout_corrector_step_trace(
name: str, values: Mapping[str, Shaped[Tensor, "..."]]
) -> StepTrace
Build the canonical Layout-Corrector trace from named tensors.
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
316 317 318 319 320 321 322 | |
compare_layout_corrector_step ¶
compare_layout_corrector_step(
reference: StepTrace,
target: StepTrace,
*,
tolerance: TensorTolerance | None = None,
) -> StepReport
Compare the package and original pre-optimizer traces exactly.
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
325 326 327 328 329 330 331 332 333 | |
compare_layout_corrector_optimizer_step ¶
compare_layout_corrector_optimizer_step(
reference_state: Mapping[str, Shaped[Tensor, "..."]],
target_state: Mapping[str, Shaped[Tensor, "..."]],
*,
tolerance: TensorTolerance | None = None,
) -> OptimizerStepReport
Compare post-step package and original parameter state exactly.
Source code in models/layout-corrector/src/layout_corrector/training/parity.py
336 337 338 339 340 341 342 343 344 | |
reference ¶
Frozen LayoutDM reference used by Layout-Corrector training.
FrozenLayoutDMReference
dataclass
¶
Package-side frozen LayoutDM model, tokenizer, and schedules.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
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 | |
from_checkpoint
classmethod
¶
from_checkpoint(
*,
dataset_name: str,
checkpoint_path: str | Path,
cluster_centers_path: str | Path,
initialization_device: device | str = "cpu",
) -> "FrozenLayoutDMReference"
Load the selected seed-0 checkpoint and preserve its state tensors.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
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 | |
to ¶
to(device: device | str) -> 'FrozenLayoutDMReference'
Move the reference model and its comparison buffers.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
143 144 145 146 147 148 149 | |
sample_time ¶
sample_time(
batch_size: int, *, device: device
) -> tuple[
Int[torch.Tensor, "batch"], Float[torch.Tensor, "batch"]
]
Use the released importance sampler and its frozen loss history.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
151 152 153 154 155 156 157 158 159 160 161 162 163 | |
corrupt ¶
corrupt(
input_ids: Int[Tensor, "batch tokens"],
timesteps: Int[Tensor, "batch"],
) -> tuple[
Int[torch.Tensor, "batch tokens"],
Float[torch.Tensor, "batch vocab tokens"],
]
Apply constrained LayoutDM corruption with reference random sampling.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
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 | |
prediction_log_probs ¶
prediction_log_probs(
log_xt: Float[Tensor, "batch vocab tokens"],
timesteps: Int[Tensor, "batch"],
) -> Float[torch.Tensor, "batch vocab tokens"]
Predict clean-token probabilities with the frozen denoiser.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
199 200 201 202 203 204 205 206 | |
reconstruct_previous ¶
reconstruct_previous(
log_x0: Float[Tensor, "batch vocab tokens"],
log_xt: Float[Tensor, "batch vocab tokens"],
timesteps: Int[Tensor, "batch"],
) -> Int[torch.Tensor, "batch tokens"]
Sample the reference x_t-1 reconstruction, excluding MASK.
Source code in models/layout-corrector/src/layout_corrector/training/reference.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |