Lace
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.
ActivationName ¶
Bases: StrEnum
Supported feed-forward activation names.
Origin
gelu2 is the VQ-Diffusion GELU2/QuickGELU branch used by the
LayoutDM, LACE, and LayoutFlow transformer utilities.
Source code in lib/laygen/src/laygen/nn/activations.py
18 19 20 21 22 23 24 25 26 27 28 | |
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 153 154 155 156 | |
__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
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 | |
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
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 | |
TimestepEmbeddingType ¶
Bases: StrEnum
Supported timestep-conditioned normalization variants.
Origin
These names come from VQ-Diffusion-derived adaptive normalization modes used by the LayoutDM and LACE checkpoint backbones.
Source code in lib/laygen/src/laygen/nn/embeddings.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
ConditionType ¶
Bases: StrEnum
Canonical condition names used by layout generation interfaces.
Source code in lib/laygen/src/laygen/common/conditions.py
9 10 11 12 13 14 15 16 17 18 19 20 21 | |
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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
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
143 144 145 146 147 148 149 150 151 152 153 154 155 | |
__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
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 | |
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
32 33 34 35 36 | |
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 | |
BetaSchedule ¶
Bases: StrEnum
Supported DDPM beta schedules.
Origin
These schedule names mirror CompVis latent-diffusion
make_beta_schedule aliases used by the LACE scheduler.
Source code in lib/laygen/src/laygen/schedulers/continuous.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
DDIMDiscretization ¶
Bases: StrEnum
Supported DDIM timestep discretization methods.
Origin
These discretization names mirror CompVis latent-diffusion
make_ddim_timesteps modes used by the LACE scheduler.
Source code in lib/laygen/src/laygen/schedulers/continuous.py
50 51 52 53 54 55 56 57 58 59 60 | |
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
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 | |
__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
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 | |
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
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 | |
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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
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
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 | |
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
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 | |
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
199 200 201 202 203 204 205 206 207 208 209 | |
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
22 23 24 25 26 27 28 29 30 31 32 | |
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 | |
normalize_activation ¶
normalize_activation(
name: ActivationName | str | ActivationFn,
) -> ActivationName | ActivationFn
Normalize an activation name while preserving custom callables.
Origin
The closed string set keeps the activation names used by VQ-Diffusion-derived LayoutDM, LACE, and LayoutFlow backbones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
ActivationName | str | ActivationFn
|
Activation enum, string value, or callable. |
required |
Returns:
| Type | Description |
|---|---|
ActivationName | ActivationFn
|
Canonical activation enum or the original callable. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the activation name is unsupported. |
Source code in lib/laygen/src/laygen/nn/activations.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
normalize_timestep_embedding ¶
normalize_timestep_embedding(
timestep_type: TimestepEmbeddingType | str | None,
) -> TimestepEmbeddingType | None
Normalize a timestep embedding mode.
Origin
This normalizes the VQ-Diffusion-derived adaptive normalization mode names exposed by LayoutDM and LACE checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestep_type
|
TimestepEmbeddingType | str | None
|
Embedding enum, string value, or |
required |
Returns:
| Type | Description |
|---|---|
TimestepEmbeddingType | None
|
Canonical embedding enum or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the embedding mode is unsupported. |
Source code in lib/laygen/src/laygen/nn/embeddings.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
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
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 | |
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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
normalize_beta_schedule ¶
normalize_beta_schedule(
schedule: BetaSchedule | str,
) -> BetaSchedule
Normalize a beta schedule value.
Origin
This preserves the CompVis latent-diffusion schedule aliases exposed by the LACE checkpoint configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schedule
|
BetaSchedule | str
|
Schedule enum or string value. |
required |
Returns:
| Type | Description |
|---|---|
BetaSchedule
|
Canonical beta schedule enum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the schedule is unsupported. |
Source code in lib/laygen/src/laygen/schedulers/continuous.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
normalize_ddim_discretization ¶
normalize_ddim_discretization(
method: DDIMDiscretization | str,
) -> DDIMDiscretization
Normalize a DDIM timestep discretization method.
Origin
This preserves the CompVis latent-diffusion DDIM discretization aliases exposed by the LACE checkpoint configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
DDIMDiscretization | str
|
Method enum or string value. |
required |
Returns:
| Type | Description |
|---|---|
DDIMDiscretization
|
Canonical DDIM discretization enum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the method is unsupported. |
Source code in lib/laygen/src/laygen/schedulers/continuous.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
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.
ActivationFn ¶
Bases: Protocol
Callable activation function for tensor-valued feed-forward blocks.
Source code in lib/laygen/src/laygen/nn/activations.py
31 32 33 34 35 36 37 38 39 | |
__call__ ¶
__call__(
input: Float[Tensor, ...],
) -> Float[torch.Tensor, ...]
Apply the activation to a tensor.
Source code in lib/laygen/src/laygen/nn/activations.py
35 36 37 38 39 | |
ActivationName ¶
Bases: StrEnum
Supported feed-forward activation names.
Origin
gelu2 is the VQ-Diffusion GELU2/QuickGELU branch used by the
LayoutDM, LACE, and LayoutFlow transformer utilities.
Source code in lib/laygen/src/laygen/nn/activations.py
18 19 20 21 22 23 24 25 26 27 28 | |
AdaInsNorm ¶
Bases: _AdaNorm
Adaptive instance normalization conditioned on diffusion timestep.
Origin
This module follows VQ-Diffusion AdaInsNorm as used by the LACE
checkpoint backbone; Diffusers has no key-compatible AdaInstanceNorm path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_embd
|
int
|
Hidden dimension. |
required |
max_timestep
|
int
|
Maximum diffusion timestep. |
required |
emb_type
|
TimestepEmbeddingType | str
|
Timestep embedding variant. |
adalayernorm_abs
|
Source code in lib/laygen/src/laygen/nn/norms.py
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 | |
__init__ ¶
__init__(
n_embd: int,
max_timestep: int,
emb_type: TimestepEmbeddingType
| str = TimestepEmbeddingType.adalayernorm_abs,
) -> None
Initialize adaptive instance normalization.
Source code in lib/laygen/src/laygen/nn/norms.py
89 90 91 92 93 94 95 96 97 | |
forward ¶
forward(
x: Float[Tensor, "batch tokens channels"],
timestep: Int[Tensor, "batch"],
) -> Float[torch.Tensor, "batch tokens channels"]
Apply timestep-conditioned instance normalization.
Source code in lib/laygen/src/laygen/nn/norms.py
99 100 101 102 103 104 105 106 107 108 109 110 | |
AdaLayerNorm ¶
Bases: _AdaNorm
Adaptive layer normalization conditioned on diffusion timestep.
Origin
This module follows VQ-Diffusion AdaLayerNorm and keeps the
submodule names used by LayoutDM, LACE, and Layout-Corrector checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_embd
|
int
|
Hidden dimension. |
required |
max_timestep
|
int
|
Maximum diffusion timestep. |
required |
emb_type
|
TimestepEmbeddingType | str
|
Timestep embedding variant. |
adalayernorm_abs
|
Source code in lib/laygen/src/laygen/nn/norms.py
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 | |
__init__ ¶
__init__(
n_embd: int,
max_timestep: int,
emb_type: TimestepEmbeddingType
| str = TimestepEmbeddingType.adalayernorm_abs,
) -> None
Initialize adaptive layer normalization.
Source code in lib/laygen/src/laygen/nn/norms.py
55 56 57 58 59 60 61 62 63 | |
forward ¶
forward(
x: Float[Tensor, "batch tokens channels"],
timestep: Int[Tensor, "batch"],
) -> Float[torch.Tensor, "batch tokens channels"]
Apply timestep-conditioned layer normalization.
Source code in lib/laygen/src/laygen/nn/norms.py
65 66 67 68 69 70 71 72 73 | |
SinusoidalPosEmb ¶
Bases: Module
Sinusoidal timestep or position embedding.
Origin
This is the VQ-Diffusion-style sinusoidal timestep embedding carried by
LayoutDM and LACE. The checkpoint operation order is preserved exactly
because LACE denoiser parity is bit-sensitive at rescale_steps=4000.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_steps
|
int
|
Maximum number of positions or timesteps. |
required |
dim
|
int
|
Embedding dimension. Odd dimensions keep the checkpoint truncation
behavior and return |
required |
rescale_steps
|
int
|
Rescaling constant used by the released checkpoints. |
4000
|
Source code in lib/laygen/src/laygen/nn/embeddings.py
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 | |
__init__ ¶
__init__(
num_steps: int, dim: int, rescale_steps: int = 4000
) -> None
Initialize the embedding parameters.
Source code in lib/laygen/src/laygen/nn/embeddings.py
76 77 78 79 80 81 | |
forward ¶
forward(
x: Int[Tensor, "batch"],
) -> Float[torch.Tensor, "batch channels"]
Embed integer positions or timesteps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Int[Tensor, 'batch']
|
One-dimensional tensor of positions. |
required |
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch channels']
|
Sinusoidal embedding tensor. |
Source code in lib/laygen/src/laygen/nn/embeddings.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
TimestepEmbeddingType ¶
Bases: StrEnum
Supported timestep-conditioned normalization variants.
Origin
These names come from VQ-Diffusion-derived adaptive normalization modes used by the LayoutDM and LACE checkpoint backbones.
Source code in lib/laygen/src/laygen/nn/embeddings.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
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 153 154 155 156 | |
__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
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 | |
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
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 | |
normalize_activation ¶
normalize_activation(
name: ActivationName | str | ActivationFn,
) -> ActivationName | ActivationFn
Normalize an activation name while preserving custom callables.
Origin
The closed string set keeps the activation names used by VQ-Diffusion-derived LayoutDM, LACE, and LayoutFlow backbones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
ActivationName | str | ActivationFn
|
Activation enum, string value, or callable. |
required |
Returns:
| Type | Description |
|---|---|
ActivationName | ActivationFn
|
Canonical activation enum or the original callable. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the activation name is unsupported. |
Source code in lib/laygen/src/laygen/nn/activations.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
normalize_timestep_embedding ¶
normalize_timestep_embedding(
timestep_type: TimestepEmbeddingType | str | None,
) -> TimestepEmbeddingType | None
Normalize a timestep embedding mode.
Origin
This normalizes the VQ-Diffusion-derived adaptive normalization mode names exposed by LayoutDM and LACE checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestep_type
|
TimestepEmbeddingType | str | None
|
Embedding enum, string value, or |
required |
Returns:
| Type | Description |
|---|---|
TimestepEmbeddingType | None
|
Canonical embedding enum or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the embedding mode is unsupported. |
Source code in lib/laygen/src/laygen/nn/embeddings.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
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
32 33 34 35 36 | |
LaceConditionAlias ¶
Bases: StrEnum
LACE-specific public condition aliases not in the shared registry.
Source code in models/lace/src/lace/pipeline_lace.py
39 40 41 42 43 44 | |
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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
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
143 144 145 146 147 148 149 150 151 152 153 154 155 | |
__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
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 | |
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
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 | |
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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
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
22 23 24 25 26 27 28 29 30 31 32 | |
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
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 | |
__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
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 | |
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
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 | |
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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
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
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 | |
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
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 | |
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
199 200 201 202 203 204 205 206 207 208 209 | |