Layout corrector
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
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 | |
__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
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 | |
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
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 | |
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
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
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
32 33 34 35 36 37 38 39 40 | |
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
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 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 | |
__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
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
__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
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 | |
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
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 | |
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
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 | |
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
32 33 34 35 36 37 38 39 40 | |
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
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 | |
__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
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 | |
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
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 | |
LayoutCorrectorModel ¶
Bases: ModelMixin, ConfigMixin
Diffusers-compatible Layout-Corrector confidence model.
Source code in models/layout-corrector/src/layout_corrector/modeling_layout_corrector.py
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 | |
__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
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 | |
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
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 | |
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
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
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
39 40 41 42 43 | |
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
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 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 | |
__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
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
__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
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 | |
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
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 | |
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
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 | |
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
46 47 48 49 50 51 52 53 | |
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 | |