Dlt
Diffusers-style DLT layout generation package.
DLTConfig ¶
Bases: ConfigMixin
Pipeline-level DLT configuration persisted with converted checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Canonical dataset name. |
'publaynet'
|
id2label
|
dict[int | str, str] | None
|
Optional public label mapping. When omitted, shared dataset labels are used. |
None
|
max_num_comp
|
int | None
|
Maximum number of layout elements. |
None
|
categories_num
|
int | None
|
Internal category count including pad and mask/drop ids. |
None
|
latent_dim
|
int
|
Transformer latent dimension. |
512
|
num_layers
|
int
|
Number of transformer encoder layers. |
4
|
num_heads
|
int
|
Number of attention heads. |
8
|
dropout_r
|
float
|
Dropout probability. |
0.0
|
activation
|
str
|
Transformer activation. |
'gelu'
|
cond_emb_size
|
int
|
Box-condition embedding size. |
224
|
cat_emb_size
|
int
|
Category embedding size. |
64
|
num_cont_timesteps
|
int
|
Continuous DDPM training timesteps. |
100
|
num_discrete_steps
|
int
|
Discrete category diffusion steps. |
10
|
beta_schedule
|
str
|
DDPM beta schedule. |
'squaredcos_cap_v2'
|
coordinate_range
|
DLTCoordinateRange | str
|
Public coordinate range. |
normalized_0_1
|
Source code in models/dlt/src/dlt/configuration_dlt.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
__init__ ¶
__init__(
*,
dataset_name: str = "publaynet",
id2label: dict[int | str, str] | None = None,
max_num_comp: int | None = None,
categories_num: int | None = None,
latent_dim: int = 512,
num_layers: int = 4,
num_heads: int = 8,
dropout_r: float = 0.0,
activation: str = "gelu",
cond_emb_size: int = 224,
cat_emb_size: int = 64,
num_cont_timesteps: int = 100,
num_discrete_steps: int = 10,
beta_schedule: str = "squaredcos_cap_v2",
coordinate_range: DLTCoordinateRange
| str = DLTCoordinateRange.normalized_0_1,
) -> None
Initialize DLT configuration.
Source code in models/dlt/src/dlt/configuration_dlt.py
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 | |
DLT ¶
Bases: ModelMixin, ConfigMixin
Joint continuous/discrete DLT denoiser.
The module names intentionally match released checkpoint keys so
model.save_pretrained directories can load without key rewriting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
categories_num
|
int
|
Internal category count including pad and mask/drop ids. |
required |
latent_dim
|
int
|
Transformer latent dimension. |
256
|
num_layers
|
int
|
Number of transformer encoder layers. |
4
|
num_heads
|
int
|
Number of attention heads. |
4
|
dropout_r
|
float
|
Dropout probability. |
0.0
|
activation
|
str
|
Transformer activation. |
'gelu'
|
cond_emb_size
|
int
|
Box-condition embedding size. |
224
|
cat_emb_size
|
int
|
Category embedding size. |
64
|
Source code in models/dlt/src/dlt/modeling_dlt.py
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 | |
__init__ ¶
__init__(
categories_num: int,
latent_dim: int = 256,
num_layers: int = 4,
num_heads: int = 4,
dropout_r: float = 0.0,
activation: str = "gelu",
cond_emb_size: int = 224,
cat_emb_size: int = 64,
) -> None
Initialize the DLT denoiser.
Source code in models/dlt/src/dlt/modeling_dlt.py
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 | |
forward ¶
forward(
sample: dict[
str,
Float[Tensor, "batch elements channels"]
| Int[Tensor, "batch elements"],
],
noisy_sample: dict[
str,
Float[Tensor, "batch elements channels"]
| Int[Tensor, "batch elements"],
],
timesteps: Int[Tensor, "batch"],
return_dict: bool = False,
) -> (
DLTModelOutput
| tuple[
Float[torch.Tensor, "batch elements 4"],
Float[torch.Tensor, "batch elements categories"],
]
)
Predict clean boxes and category logits for a noisy layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
dict[str, Float[Tensor, 'batch elements channels'] | Int[Tensor, 'batch elements']]
|
DLT-format conditioning batch with |
required |
noisy_sample
|
dict[str, Float[Tensor, 'batch elements channels'] | Int[Tensor, 'batch elements']]
|
Current noisy |
required |
timesteps
|
Int[Tensor, 'batch']
|
Continuous diffusion timestep per batch item. |
required |
return_dict
|
bool
|
Whether to return |
False
|
Returns:
| Type | Description |
|---|---|
DLTModelOutput | tuple[Float[Tensor, 'batch elements 4'], Float[Tensor, 'batch elements categories']]
|
Either a two-tuple |
DLTModelOutput | tuple[Float[Tensor, 'batch elements 4'], Float[Tensor, 'batch elements categories']]
|
callers or a dataclass output. |
Source code in models/dlt/src/dlt/modeling_dlt.py
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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
is_main_process: bool = True,
save_function: Callable[..., None] | None = None,
safe_serialization: bool = False,
variant: str | None = None,
max_shard_size: int | str = "10GB",
push_to_hub: bool = False,
use_flashpack: bool = False,
**kwargs: str | int | bool | float | None,
) -> None
Save the model with PyTorch serialization by default.
DLT keeps shared positional-encoding buffers that safetensors refuses to flatten.
Source code in models/dlt/src/dlt/modeling_dlt.py
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 | |
DLTModelOutput
dataclass
¶
Bases: BaseOutput
Output returned by the DLT denoiser.
Attributes:
| Name | Type | Description |
|---|---|---|
box |
Float[Tensor, 'batch elements 4']
|
Predicted clean internal-range boxes. |
logits |
Float[Tensor, 'batch elements categories']
|
Category logits. |
Source code in models/dlt/src/dlt/modeling_dlt.py
19 20 21 22 23 24 25 26 27 28 29 | |
DLTConditionAlias ¶
Bases: StrEnum
DLT checkpoint condition aliases.
Source code in models/dlt/src/dlt/pipeline_dlt.py
28 29 30 31 32 33 | |
DLTPipeline ¶
Bases: DiffusionPipeline
Generate layouts with a converted DLT checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
DLT
|
DLT denoiser. |
required |
scheduler
|
DLTJointDiffusionScheduler
|
Joint box/category scheduler. |
required |
config
|
DLTConfig
|
Pipeline configuration. |
required |
processor
|
DLTProcessor | None
|
Layout processor. |
None
|
Source code in models/dlt/src/dlt/pipeline_dlt.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
__init__ ¶
__init__(
model: DLT,
scheduler: DLTJointDiffusionScheduler,
config: DLTConfig,
processor: DLTProcessor | None = None,
) -> None
Initialize a DLT pipeline.
Source code in models/dlt/src/dlt/pipeline_dlt.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str
| None = ConditionType.unconditional,
labels: Int[Tensor, "batch elements"] | None = None,
bbox: Float[Tensor, "batch elements 4"] | None = None,
mask: Bool[Tensor, "batch elements"] | None = None,
num_elements: int
| list[int]
| Int[Tensor, batch]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
temperature: float | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, ...]
| Int[torch.Tensor, ...]
| Bool[torch.Tensor, ...]
| dict[int, str]
| list[Float[torch.Tensor, ...]]
| dict[str, str]
| None,
]
)
Run DLT joint denoising and return generated layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts to generate. |
1
|
seed
|
int | None
|
Optional seed used when |
None
|
generator
|
Generator | None
|
Optional torch generator. Takes precedence over |
None
|
condition_type
|
ConditionType | str | None
|
Canonical condition or DLT checkpoint alias. |
unconditional
|
labels
|
Int[Tensor, 'batch elements'] | None
|
Optional public labels for conditioned modes. |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | None
|
Optional public boxes for conditioned modes. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | list[int] | Int[Tensor, batch] | None
|
Optional valid element count for unconditional calls. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether input boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size for non-normalized boxes. |
None
|
num_inference_steps
|
int | None
|
Number of reverse diffusion steps. |
None
|
temperature
|
float | None
|
Optional category sampling temperature override. |
None
|
output_type
|
OutputType | str
|
|
dataclass
|
return_intermediates
|
bool
|
Whether to include denoising trajectory. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, ...] | Int[Tensor, ...] | Bool[Tensor, ...] | dict[int, str] | list[Float[Tensor, ...]] | dict[str, str] | None]
|
Layout generation output dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition or output type is unsupported. |
Source code in models/dlt/src/dlt/pipeline_dlt.py
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 | |
save_pretrained ¶
save_pretrained(save_directory: str | Path) -> None
Persist DLT model, scheduler, and pipeline metadata.
Source code in models/dlt/src/dlt/pipeline_dlt.py
325 326 327 328 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
) -> Self
Load a saved DLT pipeline.
Source code in models/dlt/src/dlt/pipeline_dlt.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
OutputType ¶
Bases: StrEnum
DLT pipeline output containers.
Source code in models/dlt/src/dlt/pipeline_dlt.py
21 22 23 24 25 | |
DLTProcessor ¶
Bases: ProcessorMixin
Encode DLT public inputs into the package tensor format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset name. |
required |
labels
|
Sequence[str]
|
Ordered public labels without internal pad/drop ids. |
required |
max_num_comp
|
int
|
Maximum number of layout elements. |
required |
Source code in models/dlt/src/dlt/processing_dlt.py
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 | |
categories_num
property
¶
categories_num: int
Return internal category count including pad and mask/drop ids.
__init__ ¶
__init__(
dataset: DatasetName | str,
labels: Sequence[str],
max_num_comp: int,
) -> None
Initialize processor metadata.
Source code in models/dlt/src/dlt/processing_dlt.py
43 44 45 46 47 48 49 50 51 52 53 | |
from_dataset
classmethod
¶
from_dataset(dataset: DatasetName | str) -> DLTProcessor
Create a processor from shared dataset metadata.
Source code in models/dlt/src/dlt/processing_dlt.py
55 56 57 58 59 60 61 62 63 64 65 | |
__call__ ¶
__call__(
*,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| LayoutInput,
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| LayoutInput,
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| LayoutInput
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
device: device | str | None = None,
) -> DLTProcessedBatch
Convert public layout tensors into padded internal tensors.
Source code in models/dlt/src/dlt/processing_dlt.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 118 119 120 121 122 123 124 125 126 127 128 | |
empty_condition ¶
empty_condition(
*,
batch_size: int,
device: device | str,
dtype: dtype = torch.float32,
) -> DLTProcessedBatch
Return an empty unconditional internal batch.
Source code in models/dlt/src/dlt/processing_dlt.py
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 | |
pad ¶
pad(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"] | None = None,
) -> tuple[
Float[torch.Tensor, "batch max_elements 4"],
Int[torch.Tensor, "batch max_elements"],
Bool[torch.Tensor, "batch max_elements"],
]
Pad a layout batch to max_num_comp.
Source code in models/dlt/src/dlt/processing_dlt.py
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 | |
public_to_internal_boxes ¶
public_to_internal_boxes(
bbox: Float[Tensor, "batch elements 4"],
) -> Float[torch.Tensor, "batch elements 4"]
Map public normalized xywh boxes to DLT's internal range.
Source code in models/dlt/src/dlt/processing_dlt.py
210 211 212 213 214 | |
internal_to_public_boxes ¶
internal_to_public_boxes(
bbox: Float[Tensor, "batch elements 4"],
) -> Float[torch.Tensor, "batch elements 4"]
Map DLT internal-range boxes to public normalized xywh.
Source code in models/dlt/src/dlt/processing_dlt.py
216 217 218 219 220 | |
public_to_internal_labels ¶
public_to_internal_labels(
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
) -> Int[torch.Tensor, "batch elements"]
Shift public labels into DLT's internal category ids.
Source code in models/dlt/src/dlt/processing_dlt.py
222 223 224 225 226 227 228 229 | |
internal_to_public_labels ¶
internal_to_public_labels(
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
) -> Int[torch.Tensor, "batch elements"]
Shift DLT internal category ids back to public dataset-local ids.
Source code in models/dlt/src/dlt/processing_dlt.py
231 232 233 234 235 236 237 238 | |
condition_masks ¶
condition_masks(
condition_type: str,
*,
mask: Bool[Tensor, "batch elements"],
) -> tuple[
Int[torch.Tensor, "batch elements 4"],
Int[torch.Tensor, "batch elements"],
]
Return DLT mask_box and mask_cat tensors.
1 means generated/noised and 0 means conditioned.
Source code in models/dlt/src/dlt/processing_dlt.py
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 | |
DLTJointDiffusionScheduler ¶
Bases: SchedulerMixin, ConfigMixin
Save/loadable DLT continuous and discrete diffusion scheduler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Probability of changing to a non-mask category. |
0.0
|
beta
|
float
|
Probability of changing to the mask/drop category. |
0.15
|
seq_max_length
|
int
|
Maximum number of layout elements. |
9
|
discrete_features_names
|
Sequence[Sequence[str | int]] | None
|
Discrete feature specs as |
None
|
num_discrete_steps
|
Sequence[int] | None
|
Number of discrete diffusion steps per feature. |
None
|
temperature
|
float
|
Categorical sampling temperature. |
0.8
|
num_train_timesteps
|
int
|
Continuous DDPM timesteps. |
100
|
beta_schedule
|
str
|
Diffusers DDPM beta schedule. |
'squaredcos_cap_v2'
|
prediction_type
|
str
|
DDPM prediction type. |
'sample'
|
clip_sample
|
bool
|
Whether DDPM steps clamp predicted samples. |
False
|
Source code in models/dlt/src/dlt/scheduling_dlt.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 | |
cont2disc
property
¶
cont2disc: dict[str, dict[int, int]]
Return continuous-to-discrete timestep mappings, computing lazily.
transition_matrices
property
¶
transition_matrices: dict[
str, list[Float[Tensor, "categories categories"]]
]
Return discrete transition matrices, computing lazily.
__init__ ¶
__init__(
*,
alpha: float = 0.0,
beta: float = 0.15,
seq_max_length: int = 9,
discrete_features_names: Sequence[Sequence[str | int]]
| None = None,
num_discrete_steps: Sequence[int] | None = None,
temperature: float = 0.8,
num_train_timesteps: int = 100,
beta_schedule: str = "squaredcos_cap_v2",
prediction_type: str = "sample",
clip_sample: bool = False,
) -> None
Initialize the scheduler and defer transition matrix construction.
Source code in models/dlt/src/dlt/scheduling_dlt.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
add_noise_jointly ¶
add_noise_jointly(
vec_cont: Float[Tensor, "batch elements 4"],
vec_cat: Mapping[
str, Float[Tensor, ...] | Int[Tensor, ...]
],
timesteps: Int[Tensor, batch],
noise: Float[Tensor, "batch elements 4"],
generator: Generator | None = None,
) -> tuple[
Float[torch.Tensor, "batch elements 4"],
dict[str, Int[torch.Tensor, "batch elements"]],
]
Add continuous DDPM noise and discrete categorical noise.
Source code in models/dlt/src/dlt/scheduling_dlt.py
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 | |
step_jointly ¶
step_jointly(
cont_output: Float[Tensor, "batch elements 4"],
cat_output: dict[
str, Float[Tensor, "batch elements categories"]
],
timestep: Int[Tensor, batch],
sample: Float[Tensor, "batch elements 4"],
generator: Generator | None = None,
return_dict: bool = True,
) -> tuple[
DLTJointSchedulerOutput,
dict[str, Int[torch.Tensor, "batch elements"]],
]
Take one reverse step for boxes and categories.
Source code in models/dlt/src/dlt/scheduling_dlt.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 | |
generate_transition_mat ¶
generate_transition_mat(
categories_num: int, num_discrete_steps: int
) -> list[Float[torch.Tensor, "categories categories"]]
Generate Markov transition matrices for one discrete feature.
Source code in models/dlt/src/dlt/scheduling_dlt.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
denoise_cat ¶
denoise_cat(
pred: Float[Tensor, "batch elements categories"],
t: list[int],
cat_num: int,
transition_mat_list: list[
Float[Tensor, "categories categories"]
],
generator: Generator | None = None,
) -> tuple[Int[torch.Tensor, "batch elements"], int]
Denoise a categorical feature using DLT's transition rule.
Source code in models/dlt/src/dlt/scheduling_dlt.py
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 | |
mapping_cont2disc
staticmethod
¶
mapping_cont2disc(
num_cont_steps: int, num_discrete_steps: int
) -> dict[int, int]
Map continuous timesteps onto discrete diffusion stages.
Source code in models/dlt/src/dlt/scheduling_dlt.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
build_pipeline ¶
build_pipeline(config: DLTConfig) -> DLTPipeline
Build a randomly initialized DLT pipeline from a config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DLTConfig
|
DLT configuration. |
required |
Returns:
| Type | Description |
|---|---|
DLTPipeline
|
Pipeline with model, scheduler, and processor components. |
Source code in models/dlt/src/dlt/conversion.py
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 | |
convert_save_pretrained_directory ¶
convert_save_pretrained_directory(
checkpoint_dir: str | Path,
output_dir: str | Path,
*,
config: DLTConfig,
) -> DLTPipeline
Convert an original DLT save_pretrained directory into a pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_dir
|
str | Path
|
Directory containing the original DLT model files. |
required |
output_dir
|
str | Path
|
Destination directory for the converted pipeline. |
required |
config
|
DLTConfig
|
Dataset and scheduler metadata for the checkpoint. |
required |
Returns:
| Type | Description |
|---|---|
DLTPipeline
|
The saved converted pipeline. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the checkpoint does not match the configured model. |
Source code in models/dlt/src/dlt/conversion.py
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 | |
configuration_dlt ¶
Configuration and dataset metadata for DLT pipelines.
DLTCoordinateRange ¶
Bases: StrEnum
Closed set of DLT public coordinate ranges.
Source code in models/dlt/src/dlt/configuration_dlt.py
17 18 19 20 | |
DLTConfig ¶
Bases: ConfigMixin
Pipeline-level DLT configuration persisted with converted checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Canonical dataset name. |
'publaynet'
|
id2label
|
dict[int | str, str] | None
|
Optional public label mapping. When omitted, shared dataset labels are used. |
None
|
max_num_comp
|
int | None
|
Maximum number of layout elements. |
None
|
categories_num
|
int | None
|
Internal category count including pad and mask/drop ids. |
None
|
latent_dim
|
int
|
Transformer latent dimension. |
512
|
num_layers
|
int
|
Number of transformer encoder layers. |
4
|
num_heads
|
int
|
Number of attention heads. |
8
|
dropout_r
|
float
|
Dropout probability. |
0.0
|
activation
|
str
|
Transformer activation. |
'gelu'
|
cond_emb_size
|
int
|
Box-condition embedding size. |
224
|
cat_emb_size
|
int
|
Category embedding size. |
64
|
num_cont_timesteps
|
int
|
Continuous DDPM training timesteps. |
100
|
num_discrete_steps
|
int
|
Discrete category diffusion steps. |
10
|
beta_schedule
|
str
|
DDPM beta schedule. |
'squaredcos_cap_v2'
|
coordinate_range
|
DLTCoordinateRange | str
|
Public coordinate range. |
normalized_0_1
|
Source code in models/dlt/src/dlt/configuration_dlt.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
__init__ ¶
__init__(
*,
dataset_name: str = "publaynet",
id2label: dict[int | str, str] | None = None,
max_num_comp: int | None = None,
categories_num: int | None = None,
latent_dim: int = 512,
num_layers: int = 4,
num_heads: int = 8,
dropout_r: float = 0.0,
activation: str = "gelu",
cond_emb_size: int = 224,
cat_emb_size: int = 64,
num_cont_timesteps: int = 100,
num_discrete_steps: int = 10,
beta_schedule: str = "squaredcos_cap_v2",
coordinate_range: DLTCoordinateRange
| str = DLTCoordinateRange.normalized_0_1,
) -> None
Initialize DLT configuration.
Source code in models/dlt/src/dlt/configuration_dlt.py
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 | |
normalize_dataset ¶
normalize_dataset(
dataset_name: DatasetName | str,
) -> DatasetName
Normalize and validate a DLT dataset name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Shared dataset enum or public string alias. |
required |
Returns:
| Type | Description |
|---|---|
DatasetName
|
Canonical shared dataset enum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is not a supported DLT target. |
Examples:
>>> str(normalize_dataset("rico13"))
'rico13'
Source code in models/dlt/src/dlt/configuration_dlt.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
default_id2label ¶
default_id2label(
dataset_name: DatasetName | str,
) -> dict[int, str]
Return DLT public labels for a dataset.
Source code in models/dlt/src/dlt/configuration_dlt.py
51 52 53 | |
conversion ¶
Checkpoint conversion helpers for DLT.
build_pipeline ¶
build_pipeline(config: DLTConfig) -> DLTPipeline
Build a randomly initialized DLT pipeline from a config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DLTConfig
|
DLT configuration. |
required |
Returns:
| Type | Description |
|---|---|
DLTPipeline
|
Pipeline with model, scheduler, and processor components. |
Source code in models/dlt/src/dlt/conversion.py
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 | |
convert_save_pretrained_directory ¶
convert_save_pretrained_directory(
checkpoint_dir: str | Path,
output_dir: str | Path,
*,
config: DLTConfig,
) -> DLTPipeline
Convert an original DLT save_pretrained directory into a pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_dir
|
str | Path
|
Directory containing the original DLT model files. |
required |
output_dir
|
str | Path
|
Destination directory for the converted pipeline. |
required |
config
|
DLTConfig
|
Dataset and scheduler metadata for the checkpoint. |
required |
Returns:
| Type | Description |
|---|---|
DLTPipeline
|
The saved converted pipeline. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the checkpoint does not match the configured model. |
Source code in models/dlt/src/dlt/conversion.py
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 | |
modeling_dlt ¶
DLT transformer denoiser with checkpoint state-dict key compatibility.
DLTModelOutput
dataclass
¶
Bases: BaseOutput
Output returned by the DLT denoiser.
Attributes:
| Name | Type | Description |
|---|---|---|
box |
Float[Tensor, 'batch elements 4']
|
Predicted clean internal-range boxes. |
logits |
Float[Tensor, 'batch elements categories']
|
Category logits. |
Source code in models/dlt/src/dlt/modeling_dlt.py
19 20 21 22 23 24 25 26 27 28 29 | |
PositionalEncoding ¶
Bases: Module
Sinusoidal positional encoding used by the DLT denoiser.
Source code in models/dlt/src/dlt/modeling_dlt.py
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 | |
__init__ ¶
__init__(
d_model: int, dropout: float = 0.05, max_len: int = 5000
) -> None
Create the sinusoidal encoding table.
Source code in models/dlt/src/dlt/modeling_dlt.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
forward ¶
forward(
x: Float[Tensor, "sequence batch channels"],
) -> Float[torch.Tensor, "sequence batch channels"]
Add positional encodings to a sequence tensor.
Source code in models/dlt/src/dlt/modeling_dlt.py
53 54 55 56 57 58 | |
TimestepEmbedder ¶
Bases: Module
Timestep MLP used by the DLT denoiser.
Source code in models/dlt/src/dlt/modeling_dlt.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
__init__ ¶
__init__(
latent_dim: int, seq_pos_enc: PositionalEncoding
) -> None
Initialize the timestep embedder.
Source code in models/dlt/src/dlt/modeling_dlt.py
64 65 66 67 68 69 70 71 72 | |
forward ¶
forward(
timesteps: Int[Tensor, "batch"],
) -> Float[torch.Tensor, "1 batch channels"]
Embed diffusion timesteps.
Source code in models/dlt/src/dlt/modeling_dlt.py
74 75 76 77 78 | |
DLT ¶
Bases: ModelMixin, ConfigMixin
Joint continuous/discrete DLT denoiser.
The module names intentionally match released checkpoint keys so
model.save_pretrained directories can load without key rewriting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
categories_num
|
int
|
Internal category count including pad and mask/drop ids. |
required |
latent_dim
|
int
|
Transformer latent dimension. |
256
|
num_layers
|
int
|
Number of transformer encoder layers. |
4
|
num_heads
|
int
|
Number of attention heads. |
4
|
dropout_r
|
float
|
Dropout probability. |
0.0
|
activation
|
str
|
Transformer activation. |
'gelu'
|
cond_emb_size
|
int
|
Box-condition embedding size. |
224
|
cat_emb_size
|
int
|
Category embedding size. |
64
|
Source code in models/dlt/src/dlt/modeling_dlt.py
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 | |
__init__ ¶
__init__(
categories_num: int,
latent_dim: int = 256,
num_layers: int = 4,
num_heads: int = 4,
dropout_r: float = 0.0,
activation: str = "gelu",
cond_emb_size: int = 224,
cat_emb_size: int = 64,
) -> None
Initialize the DLT denoiser.
Source code in models/dlt/src/dlt/modeling_dlt.py
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 | |
forward ¶
forward(
sample: dict[
str,
Float[Tensor, "batch elements channels"]
| Int[Tensor, "batch elements"],
],
noisy_sample: dict[
str,
Float[Tensor, "batch elements channels"]
| Int[Tensor, "batch elements"],
],
timesteps: Int[Tensor, "batch"],
return_dict: bool = False,
) -> (
DLTModelOutput
| tuple[
Float[torch.Tensor, "batch elements 4"],
Float[torch.Tensor, "batch elements categories"],
]
)
Predict clean boxes and category logits for a noisy layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
dict[str, Float[Tensor, 'batch elements channels'] | Int[Tensor, 'batch elements']]
|
DLT-format conditioning batch with |
required |
noisy_sample
|
dict[str, Float[Tensor, 'batch elements channels'] | Int[Tensor, 'batch elements']]
|
Current noisy |
required |
timesteps
|
Int[Tensor, 'batch']
|
Continuous diffusion timestep per batch item. |
required |
return_dict
|
bool
|
Whether to return |
False
|
Returns:
| Type | Description |
|---|---|
DLTModelOutput | tuple[Float[Tensor, 'batch elements 4'], Float[Tensor, 'batch elements categories']]
|
Either a two-tuple |
DLTModelOutput | tuple[Float[Tensor, 'batch elements 4'], Float[Tensor, 'batch elements categories']]
|
callers or a dataclass output. |
Source code in models/dlt/src/dlt/modeling_dlt.py
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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
is_main_process: bool = True,
save_function: Callable[..., None] | None = None,
safe_serialization: bool = False,
variant: str | None = None,
max_shard_size: int | str = "10GB",
push_to_hub: bool = False,
use_flashpack: bool = False,
**kwargs: str | int | bool | float | None,
) -> None
Save the model with PyTorch serialization by default.
DLT keeps shared positional-encoding buffers that safetensors refuses to flatten.
Source code in models/dlt/src/dlt/modeling_dlt.py
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 | |
pipeline_dlt ¶
Diffusers pipeline for DLT layout generation.
OutputType ¶
Bases: StrEnum
DLT pipeline output containers.
Source code in models/dlt/src/dlt/pipeline_dlt.py
21 22 23 24 25 | |
DLTConditionAlias ¶
Bases: StrEnum
DLT checkpoint condition aliases.
Source code in models/dlt/src/dlt/pipeline_dlt.py
28 29 30 31 32 33 | |
DLTPipeline ¶
Bases: DiffusionPipeline
Generate layouts with a converted DLT checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
DLT
|
DLT denoiser. |
required |
scheduler
|
DLTJointDiffusionScheduler
|
Joint box/category scheduler. |
required |
config
|
DLTConfig
|
Pipeline configuration. |
required |
processor
|
DLTProcessor | None
|
Layout processor. |
None
|
Source code in models/dlt/src/dlt/pipeline_dlt.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
__init__ ¶
__init__(
model: DLT,
scheduler: DLTJointDiffusionScheduler,
config: DLTConfig,
processor: DLTProcessor | None = None,
) -> None
Initialize a DLT pipeline.
Source code in models/dlt/src/dlt/pipeline_dlt.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str
| None = ConditionType.unconditional,
labels: Int[Tensor, "batch elements"] | None = None,
bbox: Float[Tensor, "batch elements 4"] | None = None,
mask: Bool[Tensor, "batch elements"] | None = None,
num_elements: int
| list[int]
| Int[Tensor, batch]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
temperature: float | None = None,
output_type: OutputType | str = OutputType.dataclass,
return_intermediates: bool = False,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, ...]
| Int[torch.Tensor, ...]
| Bool[torch.Tensor, ...]
| dict[int, str]
| list[Float[torch.Tensor, ...]]
| dict[str, str]
| None,
]
)
Run DLT joint denoising and return generated layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of layouts to generate. |
1
|
seed
|
int | None
|
Optional seed used when |
None
|
generator
|
Generator | None
|
Optional torch generator. Takes precedence over |
None
|
condition_type
|
ConditionType | str | None
|
Canonical condition or DLT checkpoint alias. |
unconditional
|
labels
|
Int[Tensor, 'batch elements'] | None
|
Optional public labels for conditioned modes. |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | None
|
Optional public boxes for conditioned modes. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | list[int] | Int[Tensor, batch] | None
|
Optional valid element count for unconditional calls. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether input boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size for non-normalized boxes. |
None
|
num_inference_steps
|
int | None
|
Number of reverse diffusion steps. |
None
|
temperature
|
float | None
|
Optional category sampling temperature override. |
None
|
output_type
|
OutputType | str
|
|
dataclass
|
return_intermediates
|
bool
|
Whether to include denoising trajectory. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, ...] | Int[Tensor, ...] | Bool[Tensor, ...] | dict[int, str] | list[Float[Tensor, ...]] | dict[str, str] | None]
|
Layout generation output dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition or output type is unsupported. |
Source code in models/dlt/src/dlt/pipeline_dlt.py
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 | |
save_pretrained ¶
save_pretrained(save_directory: str | Path) -> None
Persist DLT model, scheduler, and pipeline metadata.
Source code in models/dlt/src/dlt/pipeline_dlt.py
325 326 327 328 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | Path,
) -> Self
Load a saved DLT pipeline.
Source code in models/dlt/src/dlt/pipeline_dlt.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
normalize_condition_type ¶
normalize_condition_type(
condition_type: ConditionType | str | None,
) -> ConditionType
Normalize public and DLT alias condition names.
Source code in models/dlt/src/dlt/pipeline_dlt.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
processing_dlt ¶
Processor for DLT public layouts and internal tensors.
DLTProcessedBatch ¶
Bases: TypedDict
Padded DLT tensors consumed by the model and scheduler.
Source code in models/dlt/src/dlt/processing_dlt.py
23 24 25 26 27 28 29 | |
DLTProcessor ¶
Bases: ProcessorMixin
Encode DLT public inputs into the package tensor format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DatasetName | str
|
Canonical dataset name. |
required |
labels
|
Sequence[str]
|
Ordered public labels without internal pad/drop ids. |
required |
max_num_comp
|
int
|
Maximum number of layout elements. |
required |
Source code in models/dlt/src/dlt/processing_dlt.py
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 | |
categories_num
property
¶
categories_num: int
Return internal category count including pad and mask/drop ids.
__init__ ¶
__init__(
dataset: DatasetName | str,
labels: Sequence[str],
max_num_comp: int,
) -> None
Initialize processor metadata.
Source code in models/dlt/src/dlt/processing_dlt.py
43 44 45 46 47 48 49 50 51 52 53 | |
from_dataset
classmethod
¶
from_dataset(dataset: DatasetName | str) -> DLTProcessor
Create a processor from shared dataset metadata.
Source code in models/dlt/src/dlt/processing_dlt.py
55 56 57 58 59 60 61 62 63 64 65 | |
__call__ ¶
__call__(
*,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| LayoutInput,
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| LayoutInput,
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| LayoutInput
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
device: device | str | None = None,
) -> DLTProcessedBatch
Convert public layout tensors into padded internal tensors.
Source code in models/dlt/src/dlt/processing_dlt.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 118 119 120 121 122 123 124 125 126 127 128 | |
empty_condition ¶
empty_condition(
*,
batch_size: int,
device: device | str,
dtype: dtype = torch.float32,
) -> DLTProcessedBatch
Return an empty unconditional internal batch.
Source code in models/dlt/src/dlt/processing_dlt.py
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 | |
pad ¶
pad(
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"] | None = None,
) -> tuple[
Float[torch.Tensor, "batch max_elements 4"],
Int[torch.Tensor, "batch max_elements"],
Bool[torch.Tensor, "batch max_elements"],
]
Pad a layout batch to max_num_comp.
Source code in models/dlt/src/dlt/processing_dlt.py
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 | |
public_to_internal_boxes ¶
public_to_internal_boxes(
bbox: Float[Tensor, "batch elements 4"],
) -> Float[torch.Tensor, "batch elements 4"]
Map public normalized xywh boxes to DLT's internal range.
Source code in models/dlt/src/dlt/processing_dlt.py
210 211 212 213 214 | |
internal_to_public_boxes ¶
internal_to_public_boxes(
bbox: Float[Tensor, "batch elements 4"],
) -> Float[torch.Tensor, "batch elements 4"]
Map DLT internal-range boxes to public normalized xywh.
Source code in models/dlt/src/dlt/processing_dlt.py
216 217 218 219 220 | |
public_to_internal_labels ¶
public_to_internal_labels(
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
) -> Int[torch.Tensor, "batch elements"]
Shift public labels into DLT's internal category ids.
Source code in models/dlt/src/dlt/processing_dlt.py
222 223 224 225 226 227 228 229 | |
internal_to_public_labels ¶
internal_to_public_labels(
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
) -> Int[torch.Tensor, "batch elements"]
Shift DLT internal category ids back to public dataset-local ids.
Source code in models/dlt/src/dlt/processing_dlt.py
231 232 233 234 235 236 237 238 | |
condition_masks ¶
condition_masks(
condition_type: str,
*,
mask: Bool[Tensor, "batch elements"],
) -> tuple[
Int[torch.Tensor, "batch elements 4"],
Int[torch.Tensor, "batch elements"],
]
Return DLT mask_box and mask_cat tensors.
1 means generated/noised and 0 means conditioned.
Source code in models/dlt/src/dlt/processing_dlt.py
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 | |
scheduling_dlt ¶
Joint continuous/discrete scheduler for DLT pipelines.
DLTJointSchedulerOutput
dataclass
¶
Bases: BaseOutput
Output returned by one joint reverse step.
Source code in models/dlt/src/dlt/scheduling_dlt.py
18 19 20 21 22 23 | |
DLTJointDiffusionScheduler ¶
Bases: SchedulerMixin, ConfigMixin
Save/loadable DLT continuous and discrete diffusion scheduler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Probability of changing to a non-mask category. |
0.0
|
beta
|
float
|
Probability of changing to the mask/drop category. |
0.15
|
seq_max_length
|
int
|
Maximum number of layout elements. |
9
|
discrete_features_names
|
Sequence[Sequence[str | int]] | None
|
Discrete feature specs as |
None
|
num_discrete_steps
|
Sequence[int] | None
|
Number of discrete diffusion steps per feature. |
None
|
temperature
|
float
|
Categorical sampling temperature. |
0.8
|
num_train_timesteps
|
int
|
Continuous DDPM timesteps. |
100
|
beta_schedule
|
str
|
Diffusers DDPM beta schedule. |
'squaredcos_cap_v2'
|
prediction_type
|
str
|
DDPM prediction type. |
'sample'
|
clip_sample
|
bool
|
Whether DDPM steps clamp predicted samples. |
False
|
Source code in models/dlt/src/dlt/scheduling_dlt.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 | |
cont2disc
property
¶
cont2disc: dict[str, dict[int, int]]
Return continuous-to-discrete timestep mappings, computing lazily.
transition_matrices
property
¶
transition_matrices: dict[
str, list[Float[Tensor, "categories categories"]]
]
Return discrete transition matrices, computing lazily.
__init__ ¶
__init__(
*,
alpha: float = 0.0,
beta: float = 0.15,
seq_max_length: int = 9,
discrete_features_names: Sequence[Sequence[str | int]]
| None = None,
num_discrete_steps: Sequence[int] | None = None,
temperature: float = 0.8,
num_train_timesteps: int = 100,
beta_schedule: str = "squaredcos_cap_v2",
prediction_type: str = "sample",
clip_sample: bool = False,
) -> None
Initialize the scheduler and defer transition matrix construction.
Source code in models/dlt/src/dlt/scheduling_dlt.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
add_noise_jointly ¶
add_noise_jointly(
vec_cont: Float[Tensor, "batch elements 4"],
vec_cat: Mapping[
str, Float[Tensor, ...] | Int[Tensor, ...]
],
timesteps: Int[Tensor, batch],
noise: Float[Tensor, "batch elements 4"],
generator: Generator | None = None,
) -> tuple[
Float[torch.Tensor, "batch elements 4"],
dict[str, Int[torch.Tensor, "batch elements"]],
]
Add continuous DDPM noise and discrete categorical noise.
Source code in models/dlt/src/dlt/scheduling_dlt.py
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 | |
step_jointly ¶
step_jointly(
cont_output: Float[Tensor, "batch elements 4"],
cat_output: dict[
str, Float[Tensor, "batch elements categories"]
],
timestep: Int[Tensor, batch],
sample: Float[Tensor, "batch elements 4"],
generator: Generator | None = None,
return_dict: bool = True,
) -> tuple[
DLTJointSchedulerOutput,
dict[str, Int[torch.Tensor, "batch elements"]],
]
Take one reverse step for boxes and categories.
Source code in models/dlt/src/dlt/scheduling_dlt.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 | |
generate_transition_mat ¶
generate_transition_mat(
categories_num: int, num_discrete_steps: int
) -> list[Float[torch.Tensor, "categories categories"]]
Generate Markov transition matrices for one discrete feature.
Source code in models/dlt/src/dlt/scheduling_dlt.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
denoise_cat ¶
denoise_cat(
pred: Float[Tensor, "batch elements categories"],
t: list[int],
cat_num: int,
transition_mat_list: list[
Float[Tensor, "categories categories"]
],
generator: Generator | None = None,
) -> tuple[Int[torch.Tensor, "batch elements"], int]
Denoise a categorical feature using DLT's transition rule.
Source code in models/dlt/src/dlt/scheduling_dlt.py
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 | |
mapping_cont2disc
staticmethod
¶
mapping_cont2disc(
num_cont_steps: int, num_discrete_steps: int
) -> dict[int, int]
Map continuous timesteps onto discrete diffusion stages.
Source code in models/dlt/src/dlt/scheduling_dlt.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
training ¶
Training utilities for DLT.
callbacks ¶
Training callbacks for DLT reference-recipe reproduction.
DLTReferenceEpochSamplingCallback ¶
Bases: Callback
Consume the reference recipe's per-epoch sampling RNG.
Source code in models/dlt/src/dlt/training/callbacks.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
__init__ ¶
__init__(*, num_samples: int = 5) -> None
Store the number of validation layouts sampled after each epoch.
Source code in models/dlt/src/dlt/training/callbacks.py
62 63 64 | |
on_train_epoch_end ¶
on_train_epoch_end(
trainer: Trainer, pl_module: LightningModule
) -> None
Run reference-style validation sampling after a training epoch.
Source code in models/dlt/src/dlt/training/callbacks.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
consume_reference_epoch_sampling_rng ¶
consume_reference_epoch_sampling_rng(
pl_module: LightningModule,
val_data: _ReferenceLayoutDataset,
*,
num_samples: int = 5,
) -> None
Consume reference post-epoch sampling RNG without logging images.
Source code in models/dlt/src/dlt/training/callbacks.py
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 | |
config ¶
Small constrained training configuration types for DLT.
DLTSeedMode ¶
Bases: StrEnum
Closed set of DLT training seed modes.
Source code in models/dlt/src/dlt/training/config.py
8 9 10 11 12 | |
datamodule ¶
PyTorch Lightning data module for DLT smoke training.
DLTDataModule ¶
Bases: LightningDataModule
DLT data module with synthetic smoke data by default.
Source code in models/dlt/src/dlt/training/datamodule.py
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 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 | |
__init__ ¶
__init__(
*,
batch_size: int = 2,
num_workers: int = 0,
length: int = 8,
max_num_comp: int = 4,
categories_num: int = 7,
seed: int = 0,
data_path: str | None = None,
train_file: str = "publaynet_train.h5",
val_file: str = "publaynet_val.h5",
shuffle_train: bool = False,
) -> None
Initialize data-module parameters.
Source code in models/dlt/src/dlt/training/datamodule.py
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 | |
setup ¶
setup(stage: str | None = None) -> None
Create train/validation datasets.
Source code in models/dlt/src/dlt/training/datamodule.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
train_dataloader ¶
train_dataloader() -> DataLoader[DLTExample]
Return the train dataloader.
Source code in models/dlt/src/dlt/training/datamodule.py
69 70 71 72 73 74 75 76 77 78 79 | |
val_dataloader ¶
val_dataloader() -> DataLoader[DLTExample]
Return the validation dataloader.
Source code in models/dlt/src/dlt/training/datamodule.py
81 82 83 84 85 86 87 88 89 90 91 | |
dataset ¶
Small DLT datasets used by smoke training configs and tests.
DLTExample ¶
Bases: TypedDict
One DLT training example with conditioning masks.
Source code in models/dlt/src/dlt/training/dataset.py
14 15 16 17 18 19 20 21 22 | |
DLTStepTrace ¶
Bases: TypedDict
Diagnostic tensors captured from one DLT training step.
Source code in models/dlt/src/dlt/training/dataset.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
SyntheticDLTDataset ¶
Bases: Dataset[DLTExample]
Deterministic synthetic DLT batches that never download data.
Source code in models/dlt/src/dlt/training/dataset.py
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 | |
__init__ ¶
__init__(
*,
length: int = 8,
max_num_comp: int = 4,
categories_num: int = 7,
seed: int = 0,
) -> None
Initialize a synthetic dataset.
Source code in models/dlt/src/dlt/training/dataset.py
48 49 50 51 52 53 54 55 56 57 58 59 60 | |
__len__ ¶
__len__() -> int
Return dataset length.
Source code in models/dlt/src/dlt/training/dataset.py
62 63 64 | |
__getitem__ ¶
__getitem__(index: int) -> DLTExample
Return one deterministic synthetic DLT sample.
Source code in models/dlt/src/dlt/training/dataset.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
H5DLTDataset ¶
Bases: Dataset[DLTExample]
DLT PubLayNet dataset backed by LayoutFlow-style HDF5 files.
Source code in models/dlt/src/dlt/training/dataset.py
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__(
path: str | Path, *, max_num_comp: int = 9
) -> None
Index valid HDF5 rows without loading the full file into memory.
Source code in models/dlt/src/dlt/training/dataset.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
__len__ ¶
__len__() -> int
Return the number of valid layouts.
Source code in models/dlt/src/dlt/training/dataset.py
108 109 110 | |
__getitem__ ¶
__getitem__(index: int) -> DLTExample
Return one DLT training sample.
Source code in models/dlt/src/dlt/training/dataset.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
get_data_by_ix ¶
get_data_by_ix(
index: int,
) -> tuple[
Float[np.ndarray, "elements 4"],
Int[np.ndarray, elements],
list[int],
str,
]
Return one unpadded layout with reference-style element shuffling.
Source code in models/dlt/src/dlt/training/dataset.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
collate_dlt_batch ¶
collate_dlt_batch(examples: list[DLTExample]) -> DLTExample
Stack DLT examples into one batch.
Source code in models/dlt/src/dlt/training/dataset.py
289 290 291 292 293 294 295 296 297 298 299 300 | |
lightning_module ¶
PyTorch Lightning module for DLT training.
DLTWarmupCosineSchedulerFactory ¶
Create the warmup-cosine scheduler used for DLT training.
Source code in models/dlt/src/dlt/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 | |
__init__ ¶
__init__(
*,
num_warmup_steps: int,
num_training_steps: int | None = None,
num_cycles: float = 0.5,
last_epoch: int = -1,
) -> None
Store scheduler parameters until the optimizer is available.
Source code in models/dlt/src/dlt/training/lightning_module.py
26 27 28 29 30 31 32 33 34 35 36 37 38 | |
__call__ ¶
__call__(
optimizer: Optimizer,
*,
estimated_stepping_batches: int | None = None,
) -> LambdaLR
Build a diffusers warmup-cosine scheduler for an optimizer.
Source code in models/dlt/src/dlt/training/lightning_module.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
DLTTrainingModule ¶
Bases: LightningModule
Lightning module wrapping DLT's denoising training step.
Source code in models/dlt/src/dlt/training/lightning_module.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 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 | |
__init__ ¶
__init__(
*,
config: DLTConfig,
optimizer: OptimizerCallable = torch.optim.AdamW,
lr_scheduler: LRSchedulerCallable | None = None,
loss_box_weight: float = 5.0,
) -> None
Initialize the training module.
Source code in models/dlt/src/dlt/training/lightning_module.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
training_step ¶
training_step(
batch: DLTExample, batch_idx: int
) -> Float[torch.Tensor, ""]
Run one DLT denoising step and return the scalar loss.
Source code in models/dlt/src/dlt/training/lightning_module.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 118 119 120 121 122 123 | |
configure_optimizers ¶
configure_optimizers() -> OptimizerLRScheduler
Create optimizer and optional scheduler from LightningCLI callables.
Source code in models/dlt/src/dlt/training/lightning_module.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 | |
losses ¶
Masked losses used by DLT training.
masked_l2 ¶
masked_l2(
target: Float[Tensor, "batch elements 4"],
pred: Float[Tensor, "batch elements 4"],
mask: Int[Tensor, "batch elements 4"],
) -> Float[torch.Tensor, "batch"]
Return per-example masked squared error.
Source code in models/dlt/src/dlt/training/losses.py
10 11 12 13 14 15 16 17 18 | |
masked_cross_entropy ¶
masked_cross_entropy(
pred: Float[Tensor, "batch elements categories"],
target: Int[Tensor, "batch elements"],
mask: Int[Tensor, "batch elements"],
) -> Float[torch.Tensor, "batch"]
Return per-example masked category cross entropy.
Source code in models/dlt/src/dlt/training/losses.py
21 22 23 24 25 26 27 28 29 30 31 | |
parity ¶
DLT S0-S2 parity adapter structures.
DLTStepTrace
dataclass
¶
Comparable DLT training-step tensors.
Source code in models/dlt/src/dlt/training/parity.py
12 13 14 15 16 | |
DLTSyntheticStepTraceAdapter ¶
Trace adapter for local S0-S2 parity smoke checks.
Source code in models/dlt/src/dlt/training/parity.py
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 | |
trace_training_step ¶
trace_training_step(
module: DLTTrainingModule, batch: DLTExample
) -> DLTStepTrace
Run and collect a DLT training-step trace.
Source code in models/dlt/src/dlt/training/parity.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
seed ¶
Seed helpers for DLT training.
apply_seed_mode ¶
apply_seed_mode(mode: DLTSeedMode | str, seed: int) -> None
Apply a DLT seed mode to Python, NumPy, and torch.
Source code in models/dlt/src/dlt/training/seed.py
13 14 15 16 17 18 19 20 21 22 23 | |