Model Card for LACE¶
This package ports LACE, an ICLR 2024 layout diffusion editor, into a 🧨diffusers-style package for PubLayNet and RICO checkpoints.
Model Details¶
Model Description¶
LACE is a diffusers-style layout generator that samples layouts under learned aesthetic constraints for document and UI domains. Converted checkpoints run unconditional generation for PubLayNet, RICO25, and the RICO13 label space when the corresponding original weights are available. Public outputs use normalized center xywh boxes in [0, 1], dataset-local integer labels, a valid-element mask, and id2label.
- Developed by: Jian Chen 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: LACE repository
- Paper: OpenReview paper page
Supported Checkpoints¶
| Checkpoint | Hub ID | Status |
|---|---|---|
| PubLayNet | creative-graphic-design/lace-publaynet |
not-published; denoiser forward exact-match parity only |
| RICO13 | creative-graphic-design/lace-rico13 |
planned; public original-implementation checkpoint not present in model.tar.gz |
| RICO25 | creative-graphic-design/lace-rico25 |
not-published; denoiser forward exact-match parity only |
Uses¶
Direct Use¶
Use this package for research inference, conversion checks, and agreement checks against the original implementation for generated layouts.
LACE runs unconditional, label-conditioned, label-size-conditioned, completion, and refinement generation from converted PubLayNet and RICO checkpoints. beautify=True applies the aesthetic-constraint post-optimization used by the package.
condition_type |
Required inputs | Effect |
|---|---|---|
unconditional |
none | samples all labels and boxes |
label |
labels, bbox, optional mask |
keeps labels fixed and samples geometry |
label_size |
labels, bbox, optional mask |
keeps labels and element sizes fixed |
completion |
labels, bbox, optional mask |
preserves a random valid subset and fills the rest |
refinement |
labels, bbox, optional mask |
starts from a noised layout and refines it |
Local original checkpoints can be converted with:
uv run --package lace models/lace/scripts/convert_checkpoint.py \
--dataset publaynet \
--checkpoint .cache/lace/original/model/publaynet_best.pt \
--output .cache/lace/converted/lace-publaynet
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 shared packages when they are not published on PyPI.
pip install \
"laygen @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=lib/laygen" \
"lace @ git+https://github.com/creative-graphic-design/design-generators.git#subdirectory=models/lace"
Clone this repository, install the workspace member, and run the download and conversion steps in REPRODUCING.md. Those steps create .cache/lace/converted/lace-publaynet.
git clone https://github.com/creative-graphic-design/design-generators.git
cd design-generators
uv sync --package lace
uv run --package lace python
from lace import LacePipeline
path = ".cache/lace/converted/lace-publaynet"
# After Hub publication: from_pretrained("creative-graphic-design/lace-publaynet")
pipe = LacePipeline.from_pretrained(path)
out = pipe(batch_size=1, seed=0)
print(out.bbox.shape)
print(out.labels.shape)
print(out.id2label[int(out.labels[out.mask][0])])
print(out.mask.any().item())
torch.Size([1, 25, 4])
torch.Size([1, 25])
text
True
out = pipe(
condition_type="label_size",
labels=[[0, 1]],
bbox=[[[0.50, 0.50, 0.30, 0.20], [0.30, 0.25, 0.20, 0.10]]],
mask=[[True, True]],
beautify=True,
seed=0,
)
print(out.bbox.shape)
Training Details¶
Training Data¶
| Dataset | Dataset ID | Notes |
|---|---|---|
| RICO25 | creative-graphic-design/Rico |
ui-screenshots-and-hierarchies-with-semantic-annotations |
| RICO13 | creative-graphic-design/Rico |
original-source-derived RICO13 mapping |
| PubLayNet | creative-graphic-design/PubLayNet |
default |
The original LACE project trains on PubLayNet and RICO25 annotations prepared as max-25 layout sequences. RICO13 remains outside the package-local training claim because the approved archive has no authors' RICO13 checkpoint.
Training Procedure¶
Package-local reproduction passes the asserted staged gates for PubLayNet and RICO25 through the full TEST evaluation path; full-run statistical reproduction is not claimed. The final-head commands and machine-written evidence are recorded in TRAINING.md, and full-run reproduction is outside issue 423's scope.
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: package-local training and exact agreement checks pass through the full TEST evaluation path for PubLayNet and RICO25; full-run statistical training is not claimed.
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 | Test | Shape | Max abs | rtol | atol |
|---|---|---|---|---|---|
| PubLayNet | Denoiser logits | (2, 25, 10) |
0.0 | 0 | 0 |
| Rico25 | Denoiser logits | (2, 25, 30) |
0.0 | 0 | 0 |
Conversion smoke tests pass for PubLayNet and Rico25. Rico13 conversion agreement checks are skipped unless .cache/lace/original/model/rico13_best.pt is supplied, because the public model.tar.gz archive contains only publaynet_best.pt and rico25_best.pt. The committed agreement-check tests cover only the denoiser forward path; sampler loops, beautify, and conditional generation modes are not verified against the original implementation.
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¶
Package-local training support exists, but this PR did not perform full-run model training. Conversion, agreement checks, and any future training costs depend on the selected checkpoint and local hardware.
Technical Specifications¶
Model Architecture and Objective¶
LACE uses a continuous diffusion denoiser over layout element features. The converted LacePipeline loads checkpoint-specific category vocabularies and generates normalized center xywh boxes, category labels, and masks for PubLayNet, RICO25, or RICO13 variants.
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 lace ... from the repository root so workspace dependency sources and extras resolve correctly.
License¶
Repository wrapper code is Apache-2.0. The original LACE implementation is released under the MIT License. Upstream code, checkpoints, datasets, and prompt provider outputs keep their original licenses and terms.
Vendor links:
- Original implementation: https://github.com/puar-playground/LACE
- Checkpoints and datasets: https://huggingface.co/datasets/puar-playground/LACE
- Paper: https://openreview.net/forum?id=kJ0qp9Xdsh
Citation¶
@inproceedings{
chen2024towards,
title={Towards Aligned Layout Generation via Diffusion Model with Aesthetic Constraints},
author={Jian Chen and Ruiyi Zhang and Yufan Zhou and Changyou Chen},
booktitle={The Twelfth International Conference on Learning Representations},
year={2024},
url={https://openreview.net/forum?id=kJ0qp9Xdsh}
}
API Reference¶
Diffusers-style LACE layout generation package.
LaceDatasetSpec
dataclass
¶
Static dataset metadata used to configure a LACE checkpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
dataset |
DatasetName
|
Canonical dataset name. |
labels |
tuple[LaceLabel, ...]
|
Ordered category labels without the padding class. |
max_seq_length |
int
|
Maximum number of layout elements. |
dim_transformer |
int
|
Transformer hidden size used by the original model. |
nhead |
int
|
Number of attention heads. |
num_layers |
int
|
Number of transformer blocks. |
dim_feedforward |
int
|
Feed-forward hidden size. |
Source code in models/lace/src/lace/configuration_lace.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 | |
num_classes_with_pad
property
¶
num_classes_with_pad: int
Return the number of category channels including padding.
LaceModelOutput
dataclass
¶
Bases: BaseOutput
Output returned by the LACE transformer.
Attributes:
| Name | Type | Description |
|---|---|---|
sample |
Float[Tensor, 'batch elements channels']
|
Predicted noise tensor with the same shape as the input sample. |
Source code in models/lace/src/lace/modeling_lace.py
46 47 48 49 50 51 52 53 54 | |
LaceTransformerModel ¶
Bases: ModelMixin, ConfigMixin
Transformer denoiser for continuous LACE layout tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq_dim
|
int
|
Number of channels per layout element. |
required |
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
num_layers
|
int
|
Number of transformer blocks. |
4
|
dim_transformer
|
int
|
Hidden dimension. |
512
|
nhead
|
int
|
Number of attention heads. |
16
|
dim_feedforward
|
int
|
Feed-forward hidden dimension. |
2048
|
diffusion_step
|
int
|
Maximum diffusion timestep. |
1000
|
timestep_type
|
TimestepEmbeddingType | str | None
|
Timestep-conditioned normalization variant. |
adalayernorm
|
Source code in models/lace/src/lace/modeling_lace.py
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 | |
__init__ ¶
__init__(
*,
seq_dim: int,
max_seq_length: int = 25,
num_layers: int = 4,
dim_transformer: int = 512,
nhead: int = 16,
dim_feedforward: int = 2048,
diffusion_step: int = 1000,
timestep_type: TimestepEmbeddingType
| str
| None = TimestepEmbeddingType.adalayernorm,
) -> None
Initialize a LACE transformer denoiser.
Source code in models/lace/src/lace/modeling_lace.py
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 | |
forward ¶
forward(
sample: Float[Tensor, "batch elements channels"],
timestep: Int[Tensor, "batch"],
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
return_dict: bool = True,
) -> (
LaceModelOutput
| tuple[Float[torch.Tensor, "batch elements channels"]]
)
Predict denoising residuals for a layout sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Float[Tensor, 'batch elements channels']
|
Noisy layout tensor. |
required |
timestep
|
Int[Tensor, 'batch']
|
Diffusion timestep per sample. |
required |
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
return_dict
|
bool
|
Whether to return |
True
|
Returns:
| Type | Description |
|---|---|
LaceModelOutput | tuple[Float[Tensor, 'batch elements channels']]
|
Output dataclass or a one-item tuple containing the prediction. |
Source code in models/lace/src/lace/modeling_lace.py
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 | |
LacePipeline ¶
Bases: DiffusionPipeline
Generate layouts with a converted LACE checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LaceTransformerModel
|
LACE transformer denoiser. |
required |
scheduler
|
LaceScheduler
|
DDIM-style scheduler. |
required |
processor
|
LaceProcessor
|
Processor that encodes and decodes layout tensors. |
required |
Examples:
>>> from lace import LaceProcessor, LaceScheduler, LaceTransformerModel
>>> model = LaceTransformerModel(seq_dim=10, max_seq_length=2, num_layers=1, dim_transformer=8, nhead=2, dim_feedforward=16)
>>> pipe = LacePipeline(model=model, scheduler=LaceScheduler(ddim_num_steps=1), processor=LaceProcessor.from_dataset("publaynet"))
>>> pipe.processor.max_seq_length
25
Source code in models/lace/src/lace/pipeline_lace.py
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 | |
components
property
¶
components: dict[
str,
LaceTransformerModel | LaceScheduler | LaceProcessor,
]
Expose modules and processor metadata for Diffusers serialization.
__init__ ¶
__init__(
model: LaceTransformerModel,
scheduler: LaceScheduler,
processor: LaceProcessor,
) -> None
Attach the converted LACE denoiser, scheduler, and processor.
Source code in models/lace/src/lace/pipeline_lace.py
144 145 146 147 148 149 150 151 152 153 154 155 156 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
num_inference_steps: int | None = None,
generator: Generator | None = None,
seed: int | None = None,
condition_type: ConditionType
| str
| None = ConditionType.unconditional,
bbox: Float[Tensor, "batch elements 4"] | None = None,
labels: Int[Tensor, "batch elements"] | None = None,
mask: Bool[Tensor, "batch elements"] | None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
completion_ratio: float = 0.2,
refinement_noise: float = 0.1,
beautify: bool = False,
beautify_overlap_weight: float | None = None,
beautify_alignment_weight: float = 1.0,
output_type: PipelineOutputType
| str = PipelineOutputType.dataclass,
return_intermediates: bool = False,
) -> (
LayoutGenerationOutput
| dict[str, Shaped[torch.Tensor, "..."]]
)
Run LACE denoising and return generated layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts to generate for unconditional calls. |
1
|
num_inference_steps
|
int | None
|
Number of DDIM steps. Uses scheduler default if omitted. |
None
|
generator
|
Generator | None
|
Optional torch generator. Takes precedence over |
None
|
seed
|
int | None
|
Convenience seed used only when |
None
|
condition_type
|
ConditionType | str | None
|
Conditioning mode or alias. |
unconditional
|
bbox
|
Float[Tensor, 'batch elements 4'] | None
|
Conditioning boxes for non-unconditional modes. |
None
|
labels
|
Int[Tensor, 'batch elements'] | None
|
Conditioning labels for non-unconditional modes. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional conditioning mask. |
None
|
box_format
|
BoxFormat | str
|
Input box format for conditioning boxes. |
xywh
|
normalized
|
bool
|
Whether conditioning boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size required when |
None
|
completion_ratio
|
float
|
Maximum random completion fraction. |
0.2
|
refinement_noise
|
float
|
Noise scale for refinement conditioning. |
0.1
|
beautify
|
bool
|
Whether to run the aesthetic post-optimization. |
False
|
beautify_overlap_weight
|
float | None
|
Optional overlap penalty override. |
None
|
beautify_alignment_weight
|
float
|
Alignment penalty weight. |
1.0
|
output_type
|
PipelineOutputType | str
|
|
dataclass
|
return_intermediates
|
bool
|
Whether to return the denoising trajectory. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Shaped[Tensor, '...']]
|
Layout output dataclass or a dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a condition/output mode is unsupported or required conditioning tensors are missing. |
Source code in models/lace/src/lace/pipeline_lace.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 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 | |
save_pretrained ¶
save_pretrained(save_directory: str | Path) -> None
Save pipeline components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Output directory. |
required |
Source code in models/lace/src/lace/pipeline_lace.py
325 326 327 328 329 330 331 332 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
processor: LaceProcessor | None = None,
) -> "LacePipeline"
Load a saved LACE pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | Path
|
Local path or Hub id. |
required |
processor
|
LaceProcessor | None
|
Optional processor override. |
None
|
Returns:
| Type | Description |
|---|---|
'LacePipeline'
|
Loaded pipeline with the serialized processor attached. |
Source code in models/lace/src/lace/pipeline_lace.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
PipelineOutputType ¶
Bases: StrEnum
Supported LACE pipeline output containers.
Source code in models/lace/src/lace/pipeline_lace.py
33 34 35 36 37 | |
LaceProcessor ¶
Bases: ProcessorMixin
Encode public layout tensors into the continuous LACE sequence format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset name serialized with the processor config. |
required |
labels
|
list[str]
|
Ordered category labels without the padding label. |
required |
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
Examples:
>>> processor = LaceProcessor.from_dataset("publaynet")
>>> processor.seq_dim
10
Source code in models/lace/src/lace/processing_lace.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 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 | |
num_classes_with_pad
property
¶
num_classes_with_pad: int
Return the label-channel count including padding.
__init__ ¶
__init__(
dataset: DatasetName | str,
labels: list[str],
max_seq_length: int = 25,
) -> None
Initialize processor metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset name. |
required |
labels
|
list[str]
|
Ordered category labels without padding. |
required |
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
Source code in models/lace/src/lace/processing_lace.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
from_dataset
classmethod
¶
from_dataset(dataset: DatasetName | str) -> 'LaceProcessor'
Create a processor from built-in dataset metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
LACE dataset name or alias. |
required |
Returns:
| Type | Description |
|---|---|
'LaceProcessor'
|
Processor configured for the dataset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Examples:
>>> LaceProcessor.from_dataset("rico13").pad_label_id
13
Source code in models/lace/src/lace/processing_lace.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
__call__ ¶
__call__(
*,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| Sequence[ArrayLikeInput],
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| Sequence[ArrayLikeInput],
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Encode a public layout batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4'] | Float[ndarray, 'batch elements 4'] | Sequence[ArrayLikeInput]
|
Boxes in |
required |
labels
|
Int[Tensor, 'batch elements'] | Int[ndarray, 'batch elements'] | Sequence[ArrayLikeInput]
|
Integer category labels. |
required |
mask
|
Bool[Tensor, 'batch elements'] | Bool[ndarray, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional valid-element mask. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether input coordinates are already normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size required when |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Dictionary containing encoded layout, normalized boxes, labels, and mask. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pixel boxes are passed without |
Examples:
>>> processor = LaceProcessor.from_dataset("publaynet")
>>> out = processor(bbox=[[[0.5, 0.5, 0.2, 0.2]]], labels=[[0]])
>>> tuple(out["layout"].shape)
(1, 25, 10)
Source code in models/lace/src/lace/processing_lace.py
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 | |
pad ¶
pad(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"] | None = None,
max_seq_length: int | None = None,
) -> tuple[
Float[torch.Tensor, "batch padded_elements 4"],
Int[torch.Tensor, "batch padded_elements"],
Bool[torch.Tensor, "batch padded_elements"],
]
Pad a batch to max_seq_length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized boxes with shape |
required |
labels
|
Int[Tensor, 'batch elements']
|
Integer labels with shape |
required |
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
max_seq_length
|
int | None
|
Optional override for output length. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Tensor, 'batch padded_elements 4'], Int[Tensor, 'batch padded_elements'], Bool[Tensor, 'batch padded_elements']]
|
Padded boxes, labels, and mask. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input has too many elements. |
Source code in models/lace/src/lace/processing_lace.py
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 | |
encode ¶
encode(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"] | None = None,
) -> Float[torch.Tensor, "batch padded_elements channels"]
Encode normalized boxes and labels into the LACE latent range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized center |
required |
labels
|
Int[Tensor, 'batch elements']
|
Integer labels. |
required |
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch padded_elements channels']
|
Tensor with one-hot labels followed by box channels in |
Source code in models/lace/src/lace/processing_lace.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
decode ¶
decode(
layout: Float[Tensor, "batch elements channels"],
clamp: bool = True,
) -> LayoutGenerationOutput
Decode a LACE layout tensor into public output fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout
|
Float[Tensor, 'batch elements channels']
|
Tensor with one-hot label channels and box channels. |
required |
clamp
|
bool
|
Whether to clamp latent box channels before conversion. |
True
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput
|
Layout generation output with boxes in normalized center |
Source code in models/lace/src/lace/processing_lace.py
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 | |
save_pretrained ¶
save_pretrained(save_directory: str | Path) -> None
Save processor config to a Diffusers directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Directory where |
required |
Source code in models/lace/src/lace/processing_lace.py
268 269 270 271 272 273 274 275 276 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
cache_dir: str | Path | None = None,
force_download: bool = False,
local_files_only: bool = False,
token: str | bool | None = None,
revision: str = "main",
) -> "LaceProcessor"
Load processor config from a Diffusers directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | Path
|
Directory or Hub id containing
|
required |
cache_dir
|
str | Path | None
|
Optional Hugging Face cache directory. |
None
|
force_download
|
bool
|
Whether to force a fresh download. |
False
|
local_files_only
|
bool
|
Whether to avoid network access. |
False
|
token
|
str | bool | None
|
Optional Hugging Face token. |
None
|
revision
|
str
|
Hub revision to load. |
'main'
|
Returns:
| Type | Description |
|---|---|
'LaceProcessor'
|
Loaded processor. |
Source code in models/lace/src/lace/processing_lace.py
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 | |
LaceScheduler ¶
Bases: SchedulerMixin, ConfigMixin
Scheduler for the converted LACE diffusion process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_train_timesteps
|
int
|
Number of timesteps used during training. |
1000
|
beta_schedule
|
BetaSchedule | str
|
Beta schedule enum or string value. |
cosine
|
ddim_num_steps
|
int
|
Default number of inference steps. |
100
|
ddim_discretize
|
DDIMDiscretization | str
|
DDIM discretization enum or string value. |
uniform
|
eta
|
float
|
Stochasticity parameter used by DDIM. |
0.0
|
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
__init__ ¶
__init__(
*,
num_train_timesteps: int = 1000,
beta_schedule: BetaSchedule | str = BetaSchedule.cosine,
ddim_num_steps: int = 100,
ddim_discretize: DDIMDiscretization
| str = DDIMDiscretization.uniform,
eta: float = 0.0,
) -> None
Initialize scheduler state and default timesteps.
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
set_timesteps ¶
set_timesteps(
num_inference_steps: int | None = None,
device: device | None = None,
) -> None
Set the inference timesteps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_inference_steps
|
int | None
|
Number of denoising steps. Uses the configured default when omitted. |
None
|
device
|
device | None
|
Optional device for scheduler tensors. |
None
|
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
alphas_cumprod_for_device ¶
alphas_cumprod_for_device(
device: device | str,
) -> Float[torch.Tensor, "timesteps"]
Return training cumulative alphas computed on device.
Source code in models/lace/src/lace/scheduling_lace.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
add_noise ¶
add_noise(
original_samples: Float[
Tensor, "batch elements channels"
],
noise: Float[Tensor, "batch elements channels"],
timesteps: Int[Tensor, "batch"],
) -> Float[torch.Tensor, "batch elements channels"]
Add forward-process noise to clean samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_samples
|
Float[Tensor, 'batch elements channels']
|
Clean layout tensor. |
required |
noise
|
Float[Tensor, 'batch elements channels']
|
Noise tensor with the same shape. |
required |
timesteps
|
Int[Tensor, 'batch']
|
Per-sample timestep ids. |
required |
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch elements channels']
|
Noisy samples at the requested timesteps. |
Source code in models/lace/src/lace/scheduling_lace.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
initial_sample ¶
initial_sample(
batch_size: int,
seq_len: int,
seq_dim: int,
*,
device: device,
generator: Generator | None = None,
stochastic: bool = True,
) -> Float[torch.Tensor, "batch elements channels"]
Create the initial denoising sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts. |
required |
seq_len
|
int
|
Number of elements per layout. |
required |
seq_dim
|
int
|
Number of channels per element. |
required |
device
|
device
|
Device for the output tensor. |
required |
generator
|
Generator | None
|
Optional torch generator. |
None
|
stochastic
|
bool
|
Whether to sample noise or return zeros. |
True
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch elements channels']
|
Initial sample tensor. |
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
step ¶
step(
model_output: Float[Tensor, "batch elements channels"],
timestep: Int[Tensor, "batch"],
sample: Float[Tensor, "batch elements channels"],
index: int,
generator: Generator | None = None,
) -> LaceSchedulerOutput
Take one reverse diffusion step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output
|
Float[Tensor, 'batch elements channels']
|
Predicted noise from the denoiser. |
required |
timestep
|
Int[Tensor, 'batch']
|
Public timestep tensor, kept for scheduler compatibility. |
required |
sample
|
Float[Tensor, 'batch elements channels']
|
Current sample. |
required |
index
|
int
|
Index into the scheduler timestep buffers. |
required |
generator
|
Generator | None
|
Optional torch generator for stochastic DDIM noise. |
None
|
Returns:
| Type | Description |
|---|---|
LaceSchedulerOutput
|
Previous sample and predicted clean sample. |
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
refinement_indices ¶
refinement_indices(max_timestep: int = 201) -> list[int]
Return scheduler indices used by LACE refinement sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_timestep
|
int
|
Maximum one-indexed DDIM timestep included. |
201
|
Returns:
| Type | Description |
|---|---|
list[int]
|
Descending list of scheduler buffer indices. |
Source code in models/lace/src/lace/scheduling_lace.py
283 284 285 286 287 288 289 290 291 292 293 | |
LaceSchedulerOutput
dataclass
¶
Bases: BaseOutput
Output returned by one reverse diffusion step.
Attributes:
| Name | Type | Description |
|---|---|---|
prev_sample |
Float[Tensor, 'batch elements channels']
|
Sample for the next denoising iteration. |
pred_original_sample |
Float[Tensor, 'batch elements channels']
|
Scheduler estimate of the clean layout tensor. |
Source code in models/lace/src/lace/scheduling_lace.py
61 62 63 64 65 66 67 68 69 70 71 | |
default_model_config ¶
default_model_config(
dataset: DatasetName | str,
) -> LaceModelConfigKwargs
Build the model config for a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset enum or a supported string alias. |
required |
Returns:
| Type | Description |
|---|---|
LaceModelConfigKwargs
|
Keyword arguments accepted by |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Examples:
>>> default_model_config("rico25")["seq_dim"]
30
Source code in models/lace/src/lace/configuration_lace.py
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 | |
get_dataset_spec ¶
get_dataset_spec(
dataset: DatasetName | str,
) -> LaceDatasetSpec
Return dataset metadata for a LACE checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset enum or a supported string alias. |
required |
Returns:
| Type | Description |
|---|---|
LaceDatasetSpec
|
Dataset specification. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Examples:
>>> get_dataset_spec("publaynet").seq_dim
10
Source code in models/lace/src/lace/configuration_lace.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
normalize_dataset ¶
normalize_dataset(
dataset: DatasetName | str,
) -> DatasetName
Normalize a public dataset name to the shared dataset enum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset enum or a supported string alias. |
required |
Returns:
| Type | Description |
|---|---|
DatasetName
|
Canonical shared dataset name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Examples:
>>> str(normalize_dataset("rico13_max25"))
'rico13'
Source code in models/lace/src/lace/configuration_lace.py
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 | |
beautify_layout ¶
beautify_layout(
bbox: Float[Tensor, "batch elements 4"],
mask: Bool[Tensor, "batch elements"],
overlap_weight: float = 1.0,
alignment_weight: float = 1.0,
xy_only: bool = False,
num_steps: int = 1000,
lr: float = 0.0001,
) -> tuple[
Float[torch.Tensor, "batch elements 4"],
Bool[torch.Tensor, "batch elements"],
]
Optimize generated boxes with overlap and alignment penalties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized center |
required |
mask
|
Bool[Tensor, 'batch elements']
|
Valid-element mask with shape |
required |
overlap_weight
|
float
|
Weight for pairwise overlap penalties. |
1.0
|
alignment_weight
|
float
|
Weight for alignment penalties. |
1.0
|
xy_only
|
bool
|
Whether to keep width and height fixed. |
False
|
num_steps
|
int
|
Number of Adam optimization steps. |
1000
|
lr
|
float
|
Adam learning rate. |
0.0001
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Tensor, 'batch elements 4'], Bool[Tensor, 'batch elements']]
|
Optimized boxes and updated mask. |
Source code in models/lace/src/lace/constraints.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 107 108 109 110 111 112 113 114 | |
build_pipeline_from_vendor_checkpoint ¶
build_pipeline_from_vendor_checkpoint(
dataset: DatasetName | str,
checkpoint_path: str | Path,
ddim_num_steps: int = 100,
) -> LacePipeline
Build a LACE pipeline from a vendor checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
LACE dataset name or alias. |
required |
checkpoint_path
|
str | Path
|
Path to the vendor checkpoint. |
required |
ddim_num_steps
|
int
|
Number of DDIM inference steps configured on the scheduler. |
100
|
Returns:
| Type | Description |
|---|---|
LacePipeline
|
Pipeline containing converted model, scheduler, and processor. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the checkpoint payload is not a state dictionary. |
ValueError
|
If converted keys do not match the model architecture. |
Source code in models/lace/src/lace/conversion.py
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 | |
convert_state_dict ¶
convert_state_dict(
state_dict: Mapping[str, Shaped[Tensor, "..."]],
) -> dict[str, Shaped[torch.Tensor, "..."]]
Convert vendor parameter names to the Diffusers module names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dict
|
Mapping[str, Shaped[Tensor, '...']]
|
Vendor state dictionary. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Converted state dictionary with distributed prefixes and vendor |
dict[str, Shaped[Tensor, '...']]
|
positional buffers removed. |
Source code in models/lace/src/lace/conversion.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
load_vendor_state_dict ¶
load_vendor_state_dict(
path: str | Path,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Load a PyTorch checkpoint as a state dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a vendor checkpoint or state-dict file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Mapping from parameter names to tensors. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the checkpoint does not contain a state-dict-like object. |
Source code in models/lace/src/lace/conversion.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
lace_model_card ¶
lace_model_card(
dataset: DatasetName | str,
*,
parity_metrics: list[ParityMetric] | None = None,
) -> ModelCard
Create the Hugging Face model card for a LACE checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
LACE dataset name or alias. |
required |
parity_metrics
|
list[ParityMetric] | None
|
Optional parity metrics to embed in the evaluation section. |
None
|
Returns:
| Type | Description |
|---|---|
ModelCard
|
Rendered Hugging Face Hub model card. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Source code in models/lace/src/lace/model_card.py
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 | |
write_lace_model_card ¶
write_lace_model_card(
output_dir: str | Path,
dataset: DatasetName | str,
*,
parity_metrics: list[ParityMetric] | None = None,
) -> Path
Write the LACE model card into a model directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str | Path
|
Directory where |
required |
dataset
|
DatasetName | str
|
LACE dataset name or alias. |
required |
parity_metrics
|
list[ParityMetric] | None
|
Optional parity metrics to embed in the evaluation section. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Source code in models/lace/src/lace/model_card.py
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 | |
normalize_condition_type ¶
normalize_condition_type(
condition_type: ConditionType | str | None,
) -> ConditionType
Normalize public condition aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str | None
|
Canonical condition enum, string alias, or |
required |
Returns:
| Type | Description |
|---|---|
ConditionType
|
Canonical condition enum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition type is unsupported. |
Examples:
>>> normalize_condition_type("cwh") is ConditionType.label_size
True
Source code in models/lace/src/lace/pipeline_lace.py
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 | |
normalize_output_type ¶
normalize_output_type(
output_type: PipelineOutputType | str,
) -> PipelineOutputType
Normalize public output type aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
PipelineOutputType | str
|
Output enum or string value. |
required |
Returns:
| Type | Description |
|---|---|
PipelineOutputType
|
Canonical output type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the output type is unsupported. |
Source code in models/lace/src/lace/pipeline_lace.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
configuration_lace ¶
Dataset configuration helpers for LACE checkpoints.
LaceDatasetSpec
dataclass
¶
Static dataset metadata used to configure a LACE checkpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
dataset |
DatasetName
|
Canonical dataset name. |
labels |
tuple[LaceLabel, ...]
|
Ordered category labels without the padding class. |
max_seq_length |
int
|
Maximum number of layout elements. |
dim_transformer |
int
|
Transformer hidden size used by the original model. |
nhead |
int
|
Number of attention heads. |
num_layers |
int
|
Number of transformer blocks. |
dim_feedforward |
int
|
Feed-forward hidden size. |
Source code in models/lace/src/lace/configuration_lace.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 | |
num_classes_with_pad
property
¶
num_classes_with_pad: int
Return the number of category channels including padding.
LaceModelConfigKwargs ¶
Bases: TypedDict
Keyword arguments accepted by LaceTransformerModel.
Source code in models/lace/src/lace/configuration_lace.py
68 69 70 71 72 73 74 75 76 77 78 | |
normalize_dataset ¶
normalize_dataset(
dataset: DatasetName | str,
) -> DatasetName
Normalize a public dataset name to the shared dataset enum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset enum or a supported string alias. |
required |
Returns:
| Type | Description |
|---|---|
DatasetName
|
Canonical shared dataset name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Examples:
>>> str(normalize_dataset("rico13_max25"))
'rico13'
Source code in models/lace/src/lace/configuration_lace.py
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 | |
get_dataset_spec ¶
get_dataset_spec(
dataset: DatasetName | str,
) -> LaceDatasetSpec
Return dataset metadata for a LACE checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset enum or a supported string alias. |
required |
Returns:
| Type | Description |
|---|---|
LaceDatasetSpec
|
Dataset specification. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Examples:
>>> get_dataset_spec("publaynet").seq_dim
10
Source code in models/lace/src/lace/configuration_lace.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
default_model_config ¶
default_model_config(
dataset: DatasetName | str,
) -> LaceModelConfigKwargs
Build the model config for a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset enum or a supported string alias. |
required |
Returns:
| Type | Description |
|---|---|
LaceModelConfigKwargs
|
Keyword arguments accepted by |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Examples:
>>> default_model_config("rico25")["seq_dim"]
30
Source code in models/lace/src/lace/configuration_lace.py
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 | |
constraints ¶
Aesthetic post-processing constraints for LACE layout boxes.
beautify_layout ¶
beautify_layout(
bbox: Float[Tensor, "batch elements 4"],
mask: Bool[Tensor, "batch elements"],
overlap_weight: float = 1.0,
alignment_weight: float = 1.0,
xy_only: bool = False,
num_steps: int = 1000,
lr: float = 0.0001,
) -> tuple[
Float[torch.Tensor, "batch elements 4"],
Bool[torch.Tensor, "batch elements"],
]
Optimize generated boxes with overlap and alignment penalties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized center |
required |
mask
|
Bool[Tensor, 'batch elements']
|
Valid-element mask with shape |
required |
overlap_weight
|
float
|
Weight for pairwise overlap penalties. |
1.0
|
alignment_weight
|
float
|
Weight for alignment penalties. |
1.0
|
xy_only
|
bool
|
Whether to keep width and height fixed. |
False
|
num_steps
|
int
|
Number of Adam optimization steps. |
1000
|
lr
|
float
|
Adam learning rate. |
0.0001
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Tensor, 'batch elements 4'], Bool[Tensor, 'batch elements']]
|
Optimized boxes and updated mask. |
Source code in models/lace/src/lace/constraints.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 107 108 109 110 111 112 113 114 | |
conversion ¶
Checkpoint conversion helpers for vendor LACE weights.
load_vendor_state_dict ¶
load_vendor_state_dict(
path: str | Path,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Load a PyTorch checkpoint as a state dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a vendor checkpoint or state-dict file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Mapping from parameter names to tensors. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the checkpoint does not contain a state-dict-like object. |
Source code in models/lace/src/lace/conversion.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
convert_state_dict ¶
convert_state_dict(
state_dict: Mapping[str, Shaped[Tensor, "..."]],
) -> dict[str, Shaped[torch.Tensor, "..."]]
Convert vendor parameter names to the Diffusers module names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dict
|
Mapping[str, Shaped[Tensor, '...']]
|
Vendor state dictionary. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Converted state dictionary with distributed prefixes and vendor |
dict[str, Shaped[Tensor, '...']]
|
positional buffers removed. |
Source code in models/lace/src/lace/conversion.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
build_pipeline_from_vendor_checkpoint ¶
build_pipeline_from_vendor_checkpoint(
dataset: DatasetName | str,
checkpoint_path: str | Path,
ddim_num_steps: int = 100,
) -> LacePipeline
Build a LACE pipeline from a vendor checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
LACE dataset name or alias. |
required |
checkpoint_path
|
str | Path
|
Path to the vendor checkpoint. |
required |
ddim_num_steps
|
int
|
Number of DDIM inference steps configured on the scheduler. |
100
|
Returns:
| Type | Description |
|---|---|
LacePipeline
|
Pipeline containing converted model, scheduler, and processor. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the checkpoint payload is not a state dictionary. |
ValueError
|
If converted keys do not match the model architecture. |
Source code in models/lace/src/lace/conversion.py
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 | |
model_card ¶
Model-card generation for converted LACE checkpoints.
lace_model_card ¶
lace_model_card(
dataset: DatasetName | str,
*,
parity_metrics: list[ParityMetric] | None = None,
) -> ModelCard
Create the Hugging Face model card for a LACE checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
LACE dataset name or alias. |
required |
parity_metrics
|
list[ParityMetric] | None
|
Optional parity metrics to embed in the evaluation section. |
None
|
Returns:
| Type | Description |
|---|---|
ModelCard
|
Rendered Hugging Face Hub model card. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Source code in models/lace/src/lace/model_card.py
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 | |
write_lace_model_card ¶
write_lace_model_card(
output_dir: str | Path,
dataset: DatasetName | str,
*,
parity_metrics: list[ParityMetric] | None = None,
) -> Path
Write the LACE model card into a model directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str | Path
|
Directory where |
required |
dataset
|
DatasetName | str
|
LACE dataset name or alias. |
required |
parity_metrics
|
list[ParityMetric] | None
|
Optional parity metrics to embed in the evaluation section. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Source code in models/lace/src/lace/model_card.py
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 | |
modeling_lace ¶
Transformer denoiser used by converted LACE checkpoints.
LaceModelOutput
dataclass
¶
Bases: BaseOutput
Output returned by the LACE transformer.
Attributes:
| Name | Type | Description |
|---|---|---|
sample |
Float[Tensor, 'batch elements channels']
|
Predicted noise tensor with the same shape as the input sample. |
Source code in models/lace/src/lace/modeling_lace.py
46 47 48 49 50 51 52 53 54 | |
LaceTransformerModel ¶
Bases: ModelMixin, ConfigMixin
Transformer denoiser for continuous LACE layout tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq_dim
|
int
|
Number of channels per layout element. |
required |
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
num_layers
|
int
|
Number of transformer blocks. |
4
|
dim_transformer
|
int
|
Hidden dimension. |
512
|
nhead
|
int
|
Number of attention heads. |
16
|
dim_feedforward
|
int
|
Feed-forward hidden dimension. |
2048
|
diffusion_step
|
int
|
Maximum diffusion timestep. |
1000
|
timestep_type
|
TimestepEmbeddingType | str | None
|
Timestep-conditioned normalization variant. |
adalayernorm
|
Source code in models/lace/src/lace/modeling_lace.py
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 | |
__init__ ¶
__init__(
*,
seq_dim: int,
max_seq_length: int = 25,
num_layers: int = 4,
dim_transformer: int = 512,
nhead: int = 16,
dim_feedforward: int = 2048,
diffusion_step: int = 1000,
timestep_type: TimestepEmbeddingType
| str
| None = TimestepEmbeddingType.adalayernorm,
) -> None
Initialize a LACE transformer denoiser.
Source code in models/lace/src/lace/modeling_lace.py
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 | |
forward ¶
forward(
sample: Float[Tensor, "batch elements channels"],
timestep: Int[Tensor, "batch"],
attention_mask: Bool[Tensor, "batch elements"]
| None = None,
return_dict: bool = True,
) -> (
LaceModelOutput
| tuple[Float[torch.Tensor, "batch elements channels"]]
)
Predict denoising residuals for a layout sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Float[Tensor, 'batch elements channels']
|
Noisy layout tensor. |
required |
timestep
|
Int[Tensor, 'batch']
|
Diffusion timestep per sample. |
required |
attention_mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
return_dict
|
bool
|
Whether to return |
True
|
Returns:
| Type | Description |
|---|---|
LaceModelOutput | tuple[Float[Tensor, 'batch elements channels']]
|
Output dataclass or a one-item tuple containing the prediction. |
Source code in models/lace/src/lace/modeling_lace.py
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 | |
pipeline_lace ¶
Diffusers pipeline for LACE layout generation.
PipelineOutputType ¶
Bases: StrEnum
Supported LACE pipeline output containers.
Source code in models/lace/src/lace/pipeline_lace.py
33 34 35 36 37 | |
LaceConditionAlias ¶
Bases: StrEnum
LACE-specific public condition aliases not in the shared registry.
Source code in models/lace/src/lace/pipeline_lace.py
40 41 42 43 44 45 | |
LacePipeline ¶
Bases: DiffusionPipeline
Generate layouts with a converted LACE checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LaceTransformerModel
|
LACE transformer denoiser. |
required |
scheduler
|
LaceScheduler
|
DDIM-style scheduler. |
required |
processor
|
LaceProcessor
|
Processor that encodes and decodes layout tensors. |
required |
Examples:
>>> from lace import LaceProcessor, LaceScheduler, LaceTransformerModel
>>> model = LaceTransformerModel(seq_dim=10, max_seq_length=2, num_layers=1, dim_transformer=8, nhead=2, dim_feedforward=16)
>>> pipe = LacePipeline(model=model, scheduler=LaceScheduler(ddim_num_steps=1), processor=LaceProcessor.from_dataset("publaynet"))
>>> pipe.processor.max_seq_length
25
Source code in models/lace/src/lace/pipeline_lace.py
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 | |
components
property
¶
components: dict[
str,
LaceTransformerModel | LaceScheduler | LaceProcessor,
]
Expose modules and processor metadata for Diffusers serialization.
__init__ ¶
__init__(
model: LaceTransformerModel,
scheduler: LaceScheduler,
processor: LaceProcessor,
) -> None
Attach the converted LACE denoiser, scheduler, and processor.
Source code in models/lace/src/lace/pipeline_lace.py
144 145 146 147 148 149 150 151 152 153 154 155 156 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
num_inference_steps: int | None = None,
generator: Generator | None = None,
seed: int | None = None,
condition_type: ConditionType
| str
| None = ConditionType.unconditional,
bbox: Float[Tensor, "batch elements 4"] | None = None,
labels: Int[Tensor, "batch elements"] | None = None,
mask: Bool[Tensor, "batch elements"] | None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
completion_ratio: float = 0.2,
refinement_noise: float = 0.1,
beautify: bool = False,
beautify_overlap_weight: float | None = None,
beautify_alignment_weight: float = 1.0,
output_type: PipelineOutputType
| str = PipelineOutputType.dataclass,
return_intermediates: bool = False,
) -> (
LayoutGenerationOutput
| dict[str, Shaped[torch.Tensor, "..."]]
)
Run LACE denoising and return generated layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts to generate for unconditional calls. |
1
|
num_inference_steps
|
int | None
|
Number of DDIM steps. Uses scheduler default if omitted. |
None
|
generator
|
Generator | None
|
Optional torch generator. Takes precedence over |
None
|
seed
|
int | None
|
Convenience seed used only when |
None
|
condition_type
|
ConditionType | str | None
|
Conditioning mode or alias. |
unconditional
|
bbox
|
Float[Tensor, 'batch elements 4'] | None
|
Conditioning boxes for non-unconditional modes. |
None
|
labels
|
Int[Tensor, 'batch elements'] | None
|
Conditioning labels for non-unconditional modes. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional conditioning mask. |
None
|
box_format
|
BoxFormat | str
|
Input box format for conditioning boxes. |
xywh
|
normalized
|
bool
|
Whether conditioning boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size required when |
None
|
completion_ratio
|
float
|
Maximum random completion fraction. |
0.2
|
refinement_noise
|
float
|
Noise scale for refinement conditioning. |
0.1
|
beautify
|
bool
|
Whether to run the aesthetic post-optimization. |
False
|
beautify_overlap_weight
|
float | None
|
Optional overlap penalty override. |
None
|
beautify_alignment_weight
|
float
|
Alignment penalty weight. |
1.0
|
output_type
|
PipelineOutputType | str
|
|
dataclass
|
return_intermediates
|
bool
|
Whether to return the denoising trajectory. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Shaped[Tensor, '...']]
|
Layout output dataclass or a dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a condition/output mode is unsupported or required conditioning tensors are missing. |
Source code in models/lace/src/lace/pipeline_lace.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 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 | |
save_pretrained ¶
save_pretrained(save_directory: str | Path) -> None
Save pipeline components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Output directory. |
required |
Source code in models/lace/src/lace/pipeline_lace.py
325 326 327 328 329 330 331 332 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
processor: LaceProcessor | None = None,
) -> "LacePipeline"
Load a saved LACE pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | Path
|
Local path or Hub id. |
required |
processor
|
LaceProcessor | None
|
Optional processor override. |
None
|
Returns:
| Type | Description |
|---|---|
'LacePipeline'
|
Loaded pipeline with the serialized processor attached. |
Source code in models/lace/src/lace/pipeline_lace.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
normalize_condition_type ¶
normalize_condition_type(
condition_type: ConditionType | str | None,
) -> ConditionType
Normalize public condition aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str | None
|
Canonical condition enum, string alias, or |
required |
Returns:
| Type | Description |
|---|---|
ConditionType
|
Canonical condition enum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition type is unsupported. |
Examples:
>>> normalize_condition_type("cwh") is ConditionType.label_size
True
Source code in models/lace/src/lace/pipeline_lace.py
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 | |
normalize_output_type ¶
normalize_output_type(
output_type: PipelineOutputType | str,
) -> PipelineOutputType
Normalize public output type aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
PipelineOutputType | str
|
Output enum or string value. |
required |
Returns:
| Type | Description |
|---|---|
PipelineOutputType
|
Canonical output type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the output type is unsupported. |
Source code in models/lace/src/lace/pipeline_lace.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
processing_lace ¶
Processor for encoding and decoding LACE layout tensors.
LaceProcessor ¶
Bases: ProcessorMixin
Encode public layout tensors into the continuous LACE sequence format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset name serialized with the processor config. |
required |
labels
|
list[str]
|
Ordered category labels without the padding label. |
required |
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
Examples:
>>> processor = LaceProcessor.from_dataset("publaynet")
>>> processor.seq_dim
10
Source code in models/lace/src/lace/processing_lace.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 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 | |
num_classes_with_pad
property
¶
num_classes_with_pad: int
Return the label-channel count including padding.
__init__ ¶
__init__(
dataset: DatasetName | str,
labels: list[str],
max_seq_length: int = 25,
) -> None
Initialize processor metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset name. |
required |
labels
|
list[str]
|
Ordered category labels without padding. |
required |
max_seq_length
|
int
|
Maximum number of layout elements. |
25
|
Source code in models/lace/src/lace/processing_lace.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
from_dataset
classmethod
¶
from_dataset(dataset: DatasetName | str) -> 'LaceProcessor'
Create a processor from built-in dataset metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
LACE dataset name or alias. |
required |
Returns:
| Type | Description |
|---|---|
'LaceProcessor'
|
Processor configured for the dataset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Examples:
>>> LaceProcessor.from_dataset("rico13").pad_label_id
13
Source code in models/lace/src/lace/processing_lace.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
__call__ ¶
__call__(
*,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| Sequence[ArrayLikeInput],
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| Sequence[ArrayLikeInput],
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
) -> dict[str, Shaped[torch.Tensor, "..."]]
Encode a public layout batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4'] | Float[ndarray, 'batch elements 4'] | Sequence[ArrayLikeInput]
|
Boxes in |
required |
labels
|
Int[Tensor, 'batch elements'] | Int[ndarray, 'batch elements'] | Sequence[ArrayLikeInput]
|
Integer category labels. |
required |
mask
|
Bool[Tensor, 'batch elements'] | Bool[ndarray, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional valid-element mask. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether input coordinates are already normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size required when |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Shaped[Tensor, '...']]
|
Dictionary containing encoded layout, normalized boxes, labels, and mask. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pixel boxes are passed without |
Examples:
>>> processor = LaceProcessor.from_dataset("publaynet")
>>> out = processor(bbox=[[[0.5, 0.5, 0.2, 0.2]]], labels=[[0]])
>>> tuple(out["layout"].shape)
(1, 25, 10)
Source code in models/lace/src/lace/processing_lace.py
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 | |
pad ¶
pad(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"] | None = None,
max_seq_length: int | None = None,
) -> tuple[
Float[torch.Tensor, "batch padded_elements 4"],
Int[torch.Tensor, "batch padded_elements"],
Bool[torch.Tensor, "batch padded_elements"],
]
Pad a batch to max_seq_length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized boxes with shape |
required |
labels
|
Int[Tensor, 'batch elements']
|
Integer labels with shape |
required |
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
max_seq_length
|
int | None
|
Optional override for output length. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Tensor, 'batch padded_elements 4'], Int[Tensor, 'batch padded_elements'], Bool[Tensor, 'batch padded_elements']]
|
Padded boxes, labels, and mask. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input has too many elements. |
Source code in models/lace/src/lace/processing_lace.py
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 | |
encode ¶
encode(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"] | None = None,
) -> Float[torch.Tensor, "batch padded_elements channels"]
Encode normalized boxes and labels into the LACE latent range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized center |
required |
labels
|
Int[Tensor, 'batch elements']
|
Integer labels. |
required |
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch padded_elements channels']
|
Tensor with one-hot labels followed by box channels in |
Source code in models/lace/src/lace/processing_lace.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
decode ¶
decode(
layout: Float[Tensor, "batch elements channels"],
clamp: bool = True,
) -> LayoutGenerationOutput
Decode a LACE layout tensor into public output fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout
|
Float[Tensor, 'batch elements channels']
|
Tensor with one-hot label channels and box channels. |
required |
clamp
|
bool
|
Whether to clamp latent box channels before conversion. |
True
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput
|
Layout generation output with boxes in normalized center |
Source code in models/lace/src/lace/processing_lace.py
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 | |
save_pretrained ¶
save_pretrained(save_directory: str | Path) -> None
Save processor config to a Diffusers directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Directory where |
required |
Source code in models/lace/src/lace/processing_lace.py
268 269 270 271 272 273 274 275 276 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
cache_dir: str | Path | None = None,
force_download: bool = False,
local_files_only: bool = False,
token: str | bool | None = None,
revision: str = "main",
) -> "LaceProcessor"
Load processor config from a Diffusers directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | Path
|
Directory or Hub id containing
|
required |
cache_dir
|
str | Path | None
|
Optional Hugging Face cache directory. |
None
|
force_download
|
bool
|
Whether to force a fresh download. |
False
|
local_files_only
|
bool
|
Whether to avoid network access. |
False
|
token
|
str | bool | None
|
Optional Hugging Face token. |
None
|
revision
|
str
|
Hub revision to load. |
'main'
|
Returns:
| Type | Description |
|---|---|
'LaceProcessor'
|
Loaded processor. |
Source code in models/lace/src/lace/processing_lace.py
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 | |
scheduling_lace ¶
DDIM-style scheduler utilities for LACE layout diffusion.
LaceSchedulerOutput
dataclass
¶
Bases: BaseOutput
Output returned by one reverse diffusion step.
Attributes:
| Name | Type | Description |
|---|---|---|
prev_sample |
Float[Tensor, 'batch elements channels']
|
Sample for the next denoising iteration. |
pred_original_sample |
Float[Tensor, 'batch elements channels']
|
Scheduler estimate of the clean layout tensor. |
Source code in models/lace/src/lace/scheduling_lace.py
61 62 63 64 65 66 67 68 69 70 71 | |
LaceScheduler ¶
Bases: SchedulerMixin, ConfigMixin
Scheduler for the converted LACE diffusion process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_train_timesteps
|
int
|
Number of timesteps used during training. |
1000
|
beta_schedule
|
BetaSchedule | str
|
Beta schedule enum or string value. |
cosine
|
ddim_num_steps
|
int
|
Default number of inference steps. |
100
|
ddim_discretize
|
DDIMDiscretization | str
|
DDIM discretization enum or string value. |
uniform
|
eta
|
float
|
Stochasticity parameter used by DDIM. |
0.0
|
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
__init__ ¶
__init__(
*,
num_train_timesteps: int = 1000,
beta_schedule: BetaSchedule | str = BetaSchedule.cosine,
ddim_num_steps: int = 100,
ddim_discretize: DDIMDiscretization
| str = DDIMDiscretization.uniform,
eta: float = 0.0,
) -> None
Initialize scheduler state and default timesteps.
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
set_timesteps ¶
set_timesteps(
num_inference_steps: int | None = None,
device: device | None = None,
) -> None
Set the inference timesteps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_inference_steps
|
int | None
|
Number of denoising steps. Uses the configured default when omitted. |
None
|
device
|
device | None
|
Optional device for scheduler tensors. |
None
|
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
alphas_cumprod_for_device ¶
alphas_cumprod_for_device(
device: device | str,
) -> Float[torch.Tensor, "timesteps"]
Return training cumulative alphas computed on device.
Source code in models/lace/src/lace/scheduling_lace.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
add_noise ¶
add_noise(
original_samples: Float[
Tensor, "batch elements channels"
],
noise: Float[Tensor, "batch elements channels"],
timesteps: Int[Tensor, "batch"],
) -> Float[torch.Tensor, "batch elements channels"]
Add forward-process noise to clean samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_samples
|
Float[Tensor, 'batch elements channels']
|
Clean layout tensor. |
required |
noise
|
Float[Tensor, 'batch elements channels']
|
Noise tensor with the same shape. |
required |
timesteps
|
Int[Tensor, 'batch']
|
Per-sample timestep ids. |
required |
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch elements channels']
|
Noisy samples at the requested timesteps. |
Source code in models/lace/src/lace/scheduling_lace.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
initial_sample ¶
initial_sample(
batch_size: int,
seq_len: int,
seq_dim: int,
*,
device: device,
generator: Generator | None = None,
stochastic: bool = True,
) -> Float[torch.Tensor, "batch elements channels"]
Create the initial denoising sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts. |
required |
seq_len
|
int
|
Number of elements per layout. |
required |
seq_dim
|
int
|
Number of channels per element. |
required |
device
|
device
|
Device for the output tensor. |
required |
generator
|
Generator | None
|
Optional torch generator. |
None
|
stochastic
|
bool
|
Whether to sample noise or return zeros. |
True
|
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch elements channels']
|
Initial sample tensor. |
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
step ¶
step(
model_output: Float[Tensor, "batch elements channels"],
timestep: Int[Tensor, "batch"],
sample: Float[Tensor, "batch elements channels"],
index: int,
generator: Generator | None = None,
) -> LaceSchedulerOutput
Take one reverse diffusion step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output
|
Float[Tensor, 'batch elements channels']
|
Predicted noise from the denoiser. |
required |
timestep
|
Int[Tensor, 'batch']
|
Public timestep tensor, kept for scheduler compatibility. |
required |
sample
|
Float[Tensor, 'batch elements channels']
|
Current sample. |
required |
index
|
int
|
Index into the scheduler timestep buffers. |
required |
generator
|
Generator | None
|
Optional torch generator for stochastic DDIM noise. |
None
|
Returns:
| Type | Description |
|---|---|
LaceSchedulerOutput
|
Previous sample and predicted clean sample. |
Source code in models/lace/src/lace/scheduling_lace.py
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 | |
refinement_indices ¶
refinement_indices(max_timestep: int = 201) -> list[int]
Return scheduler indices used by LACE refinement sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_timestep
|
int
|
Maximum one-indexed DDIM timestep included. |
201
|
Returns:
| Type | Description |
|---|---|
list[int]
|
Descending list of scheduler buffer indices. |
Source code in models/lace/src/lace/scheduling_lace.py
283 284 285 286 287 288 289 290 291 292 293 | |
training ¶
Package-local LACE training entry points.
config ¶
Configuration types for package-local LACE training.
LaceSeedMode ¶
Bases: StrEnum
Regular and deterministic seed policies.
Source code in models/lace/src/lace/training/config.py
12 13 14 15 16 | |
datamodule ¶
Lightning data module for processed LACE layouts.
LaceDataModule ¶
Bases: LightningDataModule
Load processed train, validation, and test streams for LACE.
Source code in models/lace/src/lace/training/datamodule.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
__init__ ¶
__init__(
*,
processed_data_dir: str
| Path = ".cache/lace/processed",
dataset_name: LaceTrainingDatasetName = "publaynet",
batch_size: int = 256,
max_seq_length: int = 25,
num_workers: int = 4,
pin_memory: bool = True,
loader_seed: int | None = None,
) -> None
Initialize loader settings matching the original entry point.
Source code in models/lace/src/lace/training/datamodule.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
setup ¶
setup(stage: str | None = None) -> None
Open requested processed splits.
Source code in models/lace/src/lace/training/datamodule.py
45 46 47 48 49 50 51 52 | |
train_dataloader ¶
train_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."] | list[str]]
]
Return the shuffled training stream.
Source code in models/lace/src/lace/training/datamodule.py
54 55 56 57 58 | |
val_dataloader ¶
val_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."] | list[str]]
]
Return the deterministic validation stream.
Source code in models/lace/src/lace/training/datamodule.py
60 61 62 63 64 | |
test_dataloader ¶
test_dataloader() -> DataLoader[
dict[str, Shaped[torch.Tensor, "..."] | list[str]]
]
Return the deterministic test stream.
Source code in models/lace/src/lace/training/datamodule.py
66 67 68 69 70 | |
dataset ¶
Processed LayoutDM-style datasets used by the LACE training loop.
LaceProcessedDataset ¶
Bases: Dataset[dict[str, Shaped[Tensor, '...'] | str]]
Read one processed LACE split without reprocessing source annotations.
The file layout and row slicing match the original InMemoryDataset. The dataset returns variable-length rows; the package datamodule pads them in the same batch-local order as the original sparse-to-dense loader.
Source code in models/lace/src/lace/training/dataset.py
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 | |
__init__ ¶
__init__(
*,
processed_data_dir: str | Path,
dataset_name: LaceTrainingDatasetName,
split: LaceTrainingSplit,
max_seq_length: int = 25,
) -> None
Open a processed split from <dataset>-max<S>/processed.
Source code in models/lace/src/lace/training/dataset.py
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 | |
__len__ ¶
__len__() -> int
Return the number of layouts in the split.
Source code in models/lace/src/lace/training/dataset.py
66 67 68 | |
__getitem__ ¶
__getitem__(
index: int,
) -> dict[str, Shaped[torch.Tensor, "..."] | str]
Return one raw layout row with its source identifier.
Source code in models/lace/src/lace/training/dataset.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
collate_lace_batch ¶
collate_lace_batch(
batch: list[dict[str, Shaped[Tensor, "..."] | str]],
*,
max_seq_length: int = 25,
) -> dict[str, Shaped[torch.Tensor, "..."] | list[str]]
Pad a batch to the reference fixed maximum sequence length.
Source code in models/lace/src/lace/training/dataset.py
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 | |
ema ¶
Exponential moving-average state used by the LACE recipe.
LaceEMA ¶
Track trainable parameters with the original decay rule.
Source code in models/lace/src/lace/training/ema.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
__init__ ¶
__init__(*, mu: float = 0.9999) -> None
Initialize the decay coefficient and empty shadow state.
Source code in models/lace/src/lace/training/ema.py
15 16 17 18 | |
register ¶
register(module: Module) -> None
Clone every trainable parameter before the first update.
Source code in models/lace/src/lace/training/ema.py
20 21 22 23 24 25 26 | |
update ¶
update(module: Module) -> None
Apply one post-optimizer EMA update.
Source code in models/lace/src/lace/training/ema.py
28 29 30 31 32 33 34 35 36 37 38 | |
state_dict ¶
state_dict() -> dict[str, Shaped[torch.Tensor, '...']]
Return detached EMA tensors.
Source code in models/lace/src/lace/training/ema.py
40 41 42 | |
load_state_dict ¶
load_state_dict(
state_dict: Mapping[str, Shaped[Tensor, "..."]],
) -> None
Load independent EMA tensors.
Source code in models/lace/src/lace/training/ema.py
44 45 46 47 48 49 50 | |
lightning_module ¶
Lightning training module matching the effective LACE recipe.
LaceTrainingModule ¶
Bases: LightningModule
Lightning wrapper for the original plain-PyTorch training loop.
Source code in models/lace/src/lace/training/lightning_module.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 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 | |
__init__ ¶
__init__(
*,
dataset_name: LaceTrainingDatasetName = "publaynet",
model: LaceTransformerModel | None = None,
learning_rate: float = 1e-05,
batch_size: int = 256,
sample_t_max: int = 999,
feature_dim: int = 2048,
dim_transformer: int = 1024,
nhead: int = 16,
num_layers: int = 4,
ema_mu: float = 0.9999,
seed_mode: LaceSeedMode | str = LaceSeedMode.default,
seed: int = 42975,
) -> None
Initialize model, diffusion buffers, and active recipe values.
Source code in models/lace/src/lace/training/lightning_module.py
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 | |
on_fit_start ¶
on_fit_start() -> None
Apply the configured seed policy at the training boundary.
Source code in models/lace/src/lace/training/lightning_module.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
configure_optimizers ¶
configure_optimizers() -> OptimizerLRScheduler
Return the reference unscheduled Adam optimizer.
Source code in models/lace/src/lace/training/lightning_module.py
92 93 94 95 96 97 98 99 100 101 | |
on_train_batch_end ¶
on_train_batch_end(
outputs: Float[Tensor, ""]
| Mapping[str, Shaped[Tensor, "..."]]
| None,
batch: Mapping[str, Shaped[Tensor, "..."] | list[str]],
batch_idx: int,
) -> None
Update EMA after Lightning completes the optimizer step.
Source code in models/lace/src/lace/training/lightning_module.py
103 104 105 106 107 108 109 110 111 112 113 114 | |
forward_t ¶
forward_t(
layout_input: Float[Tensor, "batch elements channels"],
mask: Bool[Tensor, "batch elements"],
*,
timestep: Int[Tensor, "batch"],
) -> tuple[
Float[torch.Tensor, "four_batch elements channels"],
Float[torch.Tensor, "four_batch elements channels"],
Float[torch.Tensor, "four_batch elements channels"],
Int[torch.Tensor, "four_batch"],
]
Run the four effective conditioning branches in reference order.
Source code in models/lace/src/lace/training/lightning_module.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 | |
training_step ¶
training_step(
batch: dict[str, Shaped[Tensor, "..."] | list[str]],
batch_idx: int,
) -> Float[torch.Tensor, ""]
Run one package-local diffusion and constraint step.
Source code in models/lace/src/lace/training/lightning_module.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 | |
losses ¶
Package-local copies of the effective LACE constraint losses.
xywh_to_ltrb_reference ¶
xywh_to_ltrb_reference(
bbox: Float[Tensor, "batch elements 4"],
) -> Float[torch.Tensor, "batch elements 4"]
Convert center boxes with the reference allocation and assignments.
Source code in models/lace/src/lace/training/losses.py
11 12 13 14 15 16 17 18 19 20 | |
pairwise_iou ¶
pairwise_iou(
bbox: Float[Tensor, "batch elements 4"],
mask: Float[Tensor, "batch elements"],
) -> Float[torch.Tensor, "batch elements elements"]
Return the reference pairwise intersection-over-union matrix.
Source code in models/lace/src/lace/training/losses.py
57 58 59 60 61 62 | |
alignment_matrix ¶
alignment_matrix(
bbox: Float[Tensor, "batch elements 4"],
mask: Bool[Tensor, "batch elements"],
) -> Float[torch.Tensor, "batch elements 6 elements"]
Return the reference raw coordinate-alignment matrix.
Source code in models/lace/src/lace/training/losses.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
constraint_temporal_weight ¶
constraint_temporal_weight(
timestep: Int[Tensor, "batch"],
*,
num_timesteps: int = 1000,
end: float = 0.01,
) -> Float[torch.Tensor, "batch"]
Return the reference constant temporal constraint weight.
Source code in models/lace/src/lace/training/losses.py
99 100 101 102 103 104 105 106 107 | |
rand_fix ¶
rand_fix(
batch_size: int,
mask: Bool[Tensor, "batch elements"],
*,
ratio: float = 0.2,
) -> Bool[torch.Tensor, "batch elements"]
Sample the reference random completion mask.
Source code in models/lace/src/lace/training/losses.py
110 111 112 113 114 115 116 117 118 119 120 121 | |
lace_losses ¶
lace_losses(
*,
layout_input: Float[Tensor, "batch elements channels"],
model_output: Float[
Tensor, "four_batch elements channels"
],
noise: Float[Tensor, "four_batch elements channels"],
reconstructed: Float[
Tensor, "four_batch elements channels"
],
bbox: Float[Tensor, "four_batch elements 4"],
mask: Bool[Tensor, "four_batch elements"],
timesteps: Int[Tensor, "four_batch"],
num_classes: int,
) -> dict[str, Float[torch.Tensor, ""]]
Compute the reference-ordered diffusion, constraint, and reconstruction losses.
Source code in models/lace/src/lace/training/losses.py
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 | |
layout_alignment ¶
layout_alignment(
bbox: Float[Tensor, "batch elements 4"],
mask: Bool[Tensor, "batch elements"],
) -> tuple[
Float[torch.Tensor, "batch"],
Float[torch.Tensor, "batch"],
]
Return the reference local alignment score and normalized score.
Source code in models/lace/src/lace/training/losses.py
162 163 164 165 166 167 168 169 170 171 172 173 174 | |
seed ¶
Deterministic controls for LACE training comparisons.
apply_lace_seed_mode ¶
apply_lace_seed_mode(
seed_mode: LaceSeedMode | str, *, seed: int = 42975
) -> None
Apply the requested regular or deterministic seed policy.
Source code in models/lace/src/lace/training/seed.py
11 12 13 14 15 16 17 18 19 20 21 | |
trace ¶
Opt-in training trace callback for package evidence runs.
LaceTrainingTraceCallback ¶
Bases: Callback
Write optimizer-boundary records when a trace path is configured.
Source code in models/lace/src/lace/training/trace.py
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 | |
__init__ ¶
__init__() -> None
Initialize callback state without reading process configuration.
Source code in models/lace/src/lace/training/trace.py
62 63 64 65 66 67 68 69 | |
setup ¶
setup(
trainer: Trainer,
pl_module: LightningModule,
stage: str | None = None,
) -> None
Read the opt-in trace path when Lightning attaches the callback.
Source code in models/lace/src/lace/training/trace.py
71 72 73 74 75 76 77 | |
on_train_batch_start ¶
on_train_batch_start(
trainer: Trainer,
pl_module: LightningModule,
batch: Mapping[str, Shaped[Tensor, "..."] | list[str]],
batch_idx: int,
) -> None
Capture the current batch identifiers before its optimizer step.
Source code in models/lace/src/lace/training/trace.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
on_after_backward ¶
on_after_backward(
trainer: Trainer, pl_module: LightningModule
) -> None
Capture gradients before Lightning applies clipping.
Source code in models/lace/src/lace/training/trace.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
on_before_optimizer_step ¶
on_before_optimizer_step(
trainer: Trainer,
pl_module: LightningModule,
optimizer: Optimizer,
) -> None
Capture the loss and optimizer settings before the update.
Source code in models/lace/src/lace/training/trace.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
on_train_batch_end ¶
on_train_batch_end(
trainer: Trainer,
pl_module: LightningModule,
outputs: Shaped[Tensor, ""]
| Mapping[str, Shaped[Tensor, "..."] | list[str]]
| None,
batch: Mapping[str, Shaped[Tensor, "..."] | list[str]],
batch_idx: int,
) -> None
Capture clipped gradients and post-step state.
Source code in models/lace/src/lace/training/trace.py
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 | |
on_train_end ¶
on_train_end(
trainer: Trainer, pl_module: LightningModule
) -> None
Write records and the bounded trainer state to the trace path.
Source code in models/lace/src/lace/training/trace.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
gradient_norm ¶
gradient_norm(parameters: Mapping[str, Parameter]) -> float
Return the shared float64 gradient norm for named parameters.
Source code in models/lace/src/lace/training/trace.py
22 23 24 25 26 27 28 29 30 31 | |