Layout action
LayoutAction conversion package.
LayoutActionConfig ¶
Bases: PretrainedConfig
Architecture and tokenizer metadata for LayoutAction checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Dataset slug. |
'rico13'
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Dataset-local label mapping. |
None
|
precision
|
int
|
Coordinate precision; checkpoint defaults to 8 bits. |
8
|
max_elements
|
int | None
|
Maximum number of layout elements. |
None
|
block_size
|
int | None
|
GPT context length. Defaults to released max token length. |
None
|
vocab_size
|
int | None
|
Token vocabulary size. Defaults to the reference formula. |
None
|
n_layer
|
int
|
Number of GPT blocks. |
6
|
n_head
|
int
|
Attention heads. |
8
|
n_embd
|
int
|
Hidden size. |
512
|
embd_pdrop
|
float
|
Embedding dropout. |
0.1
|
resid_pdrop
|
float
|
Residual dropout. |
0.1
|
attn_pdrop
|
float
|
Attention dropout. |
0.1
|
default_sampling
|
LayoutActionSamplingMode | str
|
Default pipeline sampling mode. |
top_k
|
default_top_k
|
int
|
Default top-k value. |
5
|
default_temperature
|
float
|
Default sampling temperature. |
1.0
|
original_dataset_name
|
str | None
|
Original dataset name. |
None
|
original_asset_manifest
|
Mapping[str, str | int | list[str] | dict[str, AssetManifestFile]] | None
|
Optional asset manifest. |
None
|
kwargs
|
str | int | float | bool | None
|
Additional |
{}
|
Examples:
>>> config = LayoutActionConfig(dataset_name="publaynet")
>>> config.bos_token_id == config.vocab_size - 3
True
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
__init__ ¶
__init__(
*,
dataset_name: str = "rico13",
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
precision: int = 8,
max_elements: int | None = None,
block_size: int | None = None,
vocab_size: int | None = None,
n_layer: int = 6,
n_head: int = 8,
n_embd: int = 512,
embd_pdrop: float = 0.1,
resid_pdrop: float = 0.1,
attn_pdrop: float = 0.1,
default_sampling: LayoutActionSamplingMode
| str = LayoutActionSamplingMode.top_k,
default_top_k: int = 5,
default_temperature: float = 1.0,
original_dataset_name: str | None = None,
original_asset_manifest: Mapping[
str,
str
| int
| list[str]
| dict[str, AssetManifestFile],
]
| None = None,
model_type: str | None = None,
transformers_version: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize LayoutAction metadata and derived token ids.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
label_token_id ¶
label_token_id(label_id: int) -> int
Return the synthetic token id for a dataset-local label id.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
190 191 192 193 194 195 196 | |
label_id_from_token ¶
label_id_from_token(token_id: int) -> int | None
Return a dataset-local label id for a label token id.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
198 199 200 201 202 203 204 | |
object_token_id ¶
object_token_id(back_reference: int) -> int
Return the token id for a previous-object back reference.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
206 207 208 209 210 211 | |
back_reference_from_token ¶
back_reference_from_token(token_id: int) -> int | None
Return a previous-object back reference from a token id.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
213 214 215 216 217 218 | |
LayoutActionSamplingMode ¶
Bases: StrEnum
Supported token sampling modes.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
39 40 41 42 43 44 | |
StateDictKeyReport
dataclass
¶
One source-to-target state-dict mapping result.
Source code in models/layout-action/src/layout_action/conversion.py
20 21 22 23 24 25 26 27 | |
LayoutActionSamplingConfig
dataclass
¶
Sampling parameters for LayoutAction token generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
LayoutActionSamplingMode
|
Greedy, multinomial, or top-k sampling. |
top_k
|
temperature
|
float
|
Positive logit temperature. |
1.0
|
top_k
|
int | None
|
Optional top-k crop size. |
5
|
Examples:
>>> str(LayoutActionSamplingConfig().mode)
'top_k'
Source code in models/layout-action/src/layout_action/generation_layout_action.py
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 | |
from_values
classmethod
¶
from_values(
*,
mode: LayoutActionSamplingMode | str,
temperature: float,
top_k: int | None,
) -> "LayoutActionSamplingConfig"
Build a normalized sampling config from public values.
Source code in models/layout-action/src/layout_action/generation_layout_action.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
LayoutActionForCausalLM ¶
Bases: PreTrainedModel
Transformers PreTrainedModel for LayoutAction token prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutActionConfig
|
LayoutAction architecture and vocabulary metadata. |
required |
Examples:
>>> config = LayoutActionConfig(n_layer=1, n_head=2, n_embd=16, max_elements=1)
>>> model = LayoutActionForCausalLM(config)
>>> out = model(torch.tensor([[config.bos_token_id]]))
>>> out.logits.shape[-1] == config.vocab_size
True
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
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 | |
__init__ ¶
__init__(config: LayoutActionConfig) -> None
Initialize checkpoint-compatible GPT modules.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
get_block_size ¶
get_block_size() -> int
Return the maximum context length.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
127 128 129 | |
get_input_embeddings ¶
get_input_embeddings() -> nn.Embedding
Return token embeddings.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
131 132 133 | |
set_input_embeddings ¶
set_input_embeddings(value: Embedding) -> None
Replace token embeddings.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
135 136 137 | |
forward ¶
forward(
input_ids: Int[Tensor, "batch sequence"],
attention_mask: Bool[Tensor, "batch sequence"]
| None = None,
labels: Int[Tensor, "batch sequence"] | None = None,
return_dict: bool | None = None,
output_hidden_states: bool | None = None,
output_attentions: bool | None = None,
) -> (
CausalLMOutputWithCrossAttentions
| tuple[Shaped[torch.Tensor, "..."], ...]
)
Run a standard causal language-model forward pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Int[Tensor, 'batch sequence']
|
Token ids shaped |
required |
attention_mask
|
Bool[Tensor, 'batch sequence'] | None
|
Accepted for Transformers compatibility; causal masking follows the checkpoint implementation. |
None
|
labels
|
Int[Tensor, 'batch sequence'] | None
|
Optional next-token labels. |
None
|
return_dict
|
bool | None
|
Whether to return a dataclass output. |
None
|
output_hidden_states
|
bool | None
|
Include final hidden states. |
None
|
output_attentions
|
bool | None
|
Accepted for API compatibility; attentions are not materialized by the checkpoint-compatible blocks. |
None
|
Returns:
| Type | Description |
|---|---|
CausalLMOutputWithCrossAttentions | tuple[Shaped[Tensor, '...'], ...]
|
Causal LM output or tuple. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sequence length exceeds |
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
generate ¶
generate(
input_ids: Int[Tensor, "batch sequence"],
*,
max_new_tokens: int,
temperature: float = 1.0,
top_k: int | None = None,
do_sample: bool = False,
forced_token_ids: Int[Tensor, "batch sequence"]
| None = None,
generator: Generator | None = None,
) -> Int[torch.Tensor, "batch sequence"]
Generate token ids with the reference sampling loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Int[Tensor, 'batch sequence']
|
Prompt token ids. |
required |
max_new_tokens
|
int
|
Number of new tokens. |
required |
temperature
|
float
|
Sampling temperature. |
1.0
|
top_k
|
int | None
|
Optional top-k crop size. |
None
|
do_sample
|
bool
|
Whether to use multinomial sampling. If |
False
|
forced_token_ids
|
Int[Tensor, 'batch sequence'] | None
|
Optional ids to force at each generation step. |
None
|
generator
|
Generator | None
|
Optional torch generator for multinomial sampling. |
None
|
Returns:
| Type | Description |
|---|---|
Int[Tensor, 'batch sequence']
|
Prompt plus generated token ids. |
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
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 | |
LayoutActionPipeline ¶
Bases: LayoutGenerationPipeline
Compose a LayoutAction model and processor for layout generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LayoutActionForCausalLM
|
Converted LayoutAction causal LM. |
required |
processor
|
LayoutActionProcessor
|
Matching processor/tokenizer. |
required |
config
|
LayoutActionConfig | None
|
Optional root pipeline config. Defaults to |
None
|
Examples:
>>> config = LayoutActionConfig(n_layer=1, n_head=2, n_embd=16, max_elements=1)
>>> pipe = LayoutActionPipeline(
... model=LayoutActionForCausalLM(config),
... processor=LayoutActionProcessor(LayoutActionTokenizer(config)),
... config=config,
... )
>>> pipe.config.model_type
'layout-action'
Source code in models/layout-action/src/layout_action/pipeline_layout_action.py
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 | |
__init__ ¶
__init__(
model: LayoutActionForCausalLM,
processor: LayoutActionProcessor,
config: LayoutActionConfig | None = None,
) -> None
Initialize the pipeline.
Source code in models/layout-action/src/layout_action/pipeline_layout_action.py
99 100 101 102 103 104 105 106 107 108 109 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.unconditional,
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| Sequence[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
output_type: OutputType = "dataclass",
return_intermediates: bool = False,
sampling: Literal[
"greedy", "multinomial", "top_k"
] = "top_k",
temperature: float = 1.0,
top_k: int | None = 5,
) -> LayoutGenerationOutput | LayoutActionOutputDict
Generate a layout through the public LayoutAction interface.
Source code in models/layout-action/src/layout_action/pipeline_layout_action.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
LayoutActionProcessor ¶
Bases: ProcessorMixin
Prepare LayoutAction prompts and decode generated action sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
LayoutActionTokenizer
|
LayoutAction tokenizer. |
required |
Examples:
>>> processor = LayoutActionProcessor(LayoutActionTokenizer(LayoutActionConfig(max_elements=1)))
>>> encoded = processor(condition_type="unconditional")
>>> encoded["input_ids"].shape
torch.Size([1, 1])
Source code in models/layout-action/src/layout_action/processing_layout_action.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 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 | |
__init__ ¶
__init__(tokenizer: LayoutActionTokenizer) -> None
Initialize the processor.
Source code in models/layout-action/src/layout_action/processing_layout_action.py
62 63 64 65 | |
__call__ ¶
__call__(
*,
condition_type: ConditionType
| str = ConditionType.unconditional,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| Sequence[ArrayLikeInput]
| None = None,
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
batch_size: int = 1,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Encode a public generation condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str
|
Canonical condition or supported release alias. |
unconditional
|
bbox
|
Float[Tensor, 'batch elements 4'] | Float[ndarray, 'batch elements 4'] | Sequence[ArrayLikeInput] | None
|
Optional public boxes for completion prompts. |
None
|
labels
|
Int[Tensor, 'batch elements'] | Int[ndarray, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional labels for label/completion prompts. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Bool[ndarray, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Optional element count or completion prefix length. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Canvas size for pixel boxes. |
None
|
batch_size
|
int
|
Batch size for unconditional generation. |
1
|
return_tensors
|
Literal['pt']
|
Tensor framework. Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding with prompt ids and optional forced token ids. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the condition is unsupported by LayoutAction. |
ValueError
|
If required condition payloads are missing. |
Source code in models/layout-action/src/layout_action/processing_layout_action.py
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 | |
post_process_layouts ¶
post_process_layouts(
sequences: Int[Tensor, "batch tokens"],
*,
output_type: OutputType = "dataclass",
return_intermediates: bool = False,
) -> LayoutGenerationOutput | LayoutActionOutputDict
Decode generated sequences to the common output schema.
Source code in models/layout-action/src/layout_action/processing_layout_action.py
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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
push_to_hub: bool = False,
**kwargs: str | int | float | bool | None,
) -> None
Save processor and tokenizer metadata.
Source code in models/layout-action/src/layout_action/processing_layout_action.py
233 234 235 236 237 238 239 240 241 242 243 244 245 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | PathLike[str],
cache_dir: str | PathLike[str] | None = None,
force_download: bool = False,
local_files_only: bool = False,
token: str | bool | None = None,
revision: str = "main",
**kwargs: str | int | float | bool | None,
) -> "LayoutActionProcessor"
Load processor metadata from a checkpoint directory or Hub repo id.
Source code in models/layout-action/src/layout_action/processing_layout_action.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
LayoutActionTokenizer ¶
Bases: PreTrainedTokenizer
PreTrainedTokenizer for LayoutAction's 13-token element grammar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutActionConfig | None
|
LayoutAction config carrying vocabulary metadata. |
None
|
tokenizer_config_file
|
str | None
|
Optional saved tokenizer metadata path. |
None
|
kwargs
|
str | int | float | bool | None
|
Standard tokenizer keyword arguments. |
{}
|
Examples:
>>> tokenizer = LayoutActionTokenizer(LayoutActionConfig(max_elements=2))
>>> tokenizer.bos_token_id == tokenizer.config.bos_token_id
True
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
__init__ ¶
__init__(
config: LayoutActionConfig | None = None,
tokenizer_config_file: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize synthetic token strings.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
get_vocab ¶
get_vocab() -> dict[str, int]
Return synthetic token strings mapped to ids.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
94 95 96 | |
convert_tokens_to_string ¶
convert_tokens_to_string(tokens: list[str]) -> str
Join synthetic layout tokens.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
110 111 112 | |
save_vocabulary ¶
save_vocabulary(
save_directory: str | PathLike[str],
filename_prefix: str | None = None,
) -> tuple[str, ...]
Save tokenizer metadata.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | PathLike[str],
*inputs: str,
cache_dir: str | PathLike[str] | None = None,
force_download: bool = False,
local_files_only: bool = False,
token: str | bool | None = None,
revision: str = "main",
**kwargs: str | int | float | bool | None,
) -> "LayoutActionTokenizer"
Load tokenizer metadata through the standard Transformers resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Local tokenizer directory or Hub repo id. |
required |
inputs
|
str
|
Reserved tokenizer inputs. |
()
|
cache_dir
|
str | PathLike[str] | None
|
Cache directory for Hub-backed files. |
None
|
force_download
|
bool
|
Whether to refresh cached files. |
False
|
local_files_only
|
bool
|
Whether to disable network resolution. |
False
|
token
|
str | bool | None
|
Hugging Face token. |
None
|
revision
|
str
|
Hub revision. |
'main'
|
kwargs
|
str | int | float | bool | None
|
Standard tokenizer keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
'LayoutActionTokenizer'
|
Loaded LayoutAction tokenizer. |
Source code in models/layout-action/src/layout_action/tokenization_layout_action.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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
quantize_bbox ¶
quantize_bbox(
bbox: Float[Tensor, "... 4"],
) -> Int[torch.Tensor, "... 4"]
Quantize normalized center xywh boxes with checkpoint binning.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
179 180 181 182 183 184 185 186 187 188 189 | |
continuize_bbox ¶
continuize_bbox(
quantized_bbox: Int[Tensor, "... 4"],
) -> Float[torch.Tensor, "... 4"]
Decode quantized boxes to normalized center xywh values.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
191 192 193 194 195 196 197 | |
encode_layout ¶
encode_layout(
*,
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
) -> Int[torch.Tensor, "batch tokens"]
Encode public normalized layouts to padded action-token sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized center |
required |
labels
|
Int[Tensor, 'batch elements']
|
Dataset-local labels shaped |
required |
mask
|
Bool[Tensor, 'batch elements']
|
Valid-element mask shaped |
required |
Returns:
| Type | Description |
|---|---|
Int[Tensor, 'batch tokens']
|
Token ids shaped |
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
encode_action_layout ¶
encode_action_layout(
*,
quantized_bbox: Int[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
) -> Int[torch.Tensor, "batch tokens"]
Encode already quantized boxes to action tokens.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
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 | |
decode_layout ¶
decode_layout(
input_ids: Int[Tensor, "batch_or_tokens ..."],
) -> dict[str, Shaped[torch.Tensor, "..."]]
Decode action-token sequences to public layout tensors.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
337 338 339 340 341 342 343 344 | |
decode_action_tokens ¶
decode_action_tokens(
input_ids: Int[Tensor, "batch_or_tokens ..."],
*,
return_actions: bool = False,
) -> dict[
str,
Shaped[torch.Tensor, "..."]
| dict[str, Shaped[torch.Tensor, "..."]],
]
Decode action tokens and optionally return raw action details.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
convert_layout_action_checkpoint ¶
convert_layout_action_checkpoint(
*,
checkpoint: str | Path,
output_dir: str | Path,
config: LayoutActionConfig,
strict: bool = True,
) -> LayoutActionConversionReport
Convert a raw vendor .pth checkpoint to HF-style files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint
|
str | Path
|
Raw PyTorch state-dict path. |
required |
output_dir
|
str | Path
|
Destination checkpoint directory. |
required |
config
|
LayoutActionConfig
|
LayoutAction config built from dataset metadata. |
required |
strict
|
bool
|
Whether model loading is strict. |
True
|
Returns:
| Type | Description |
|---|---|
LayoutActionConversionReport
|
Conversion report dictionary. |
Source code in models/layout-action/src/layout_action/conversion.py
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 | |
remap_layout_action_key ¶
remap_layout_action_key(key: str) -> str
Map a vendor LayoutAction state-dict key to this package.
Source code in models/layout-action/src/layout_action/conversion.py
60 61 62 | |
remap_state_dict ¶
remap_state_dict(
state_dict: dict[str, Shaped[Tensor, "..."]],
model: LayoutActionForCausalLM,
) -> tuple[
dict[str, Shaped[torch.Tensor, "..."]],
list[StateDictKeyReport],
]
Remap and report checkpoint key coverage.
Source code in models/layout-action/src/layout_action/conversion.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
sample_action_tokens ¶
sample_action_tokens(
model: ActionTokenModel,
input_ids: Int[Tensor, "batch sequence"],
*,
max_new_tokens: int,
sampling: LayoutActionSamplingConfig,
forced_token_ids: Int[Tensor, "batch new_tokens"]
| None = None,
generator: Generator | None = None,
) -> Int[torch.Tensor, "batch sequence"]
Autoregressively sample LayoutAction token ids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
ActionTokenModel
|
Token model returning logits. |
required |
input_ids
|
Int[Tensor, 'batch sequence']
|
Prompt ids shaped |
required |
max_new_tokens
|
int
|
Number of new tokens to append. |
required |
sampling
|
LayoutActionSamplingConfig
|
Sampling parameters. |
required |
forced_token_ids
|
Int[Tensor, 'batch new_tokens'] | None
|
Optional ids shaped |
None
|
generator
|
Generator | None
|
Optional torch generator for multinomial sampling. |
None
|
Returns:
| Type | Description |
|---|---|
Int[Tensor, 'batch sequence']
|
Prompt plus sampled token ids. |
Source code in models/layout-action/src/layout_action/generation_layout_action.py
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 | |
top_k_logits ¶
top_k_logits(
logits: Float[Tensor, "batch vocab"], k: int
) -> Float[torch.Tensor, "batch vocab"]
Mask logits outside the top k values exactly like the reference helper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Float[Tensor, 'batch vocab']
|
Logits shaped |
required |
k
|
int
|
Number of top logits to keep. |
required |
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch vocab']
|
Logits with non-top-k entries set to negative infinity. |
Source code in models/layout-action/src/layout_action/generation_layout_action.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
configuration_layout_action ¶
Configuration for converted LayoutAction checkpoints.
AssetManifestFile ¶
Bases: TypedDict
One inventoried original asset.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
20 21 22 23 24 | |
LayoutActionAssetManifest ¶
Bases: TypedDict
Original LayoutAction asset manifest.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
27 28 29 30 31 32 33 34 35 36 | |
LayoutActionSamplingMode ¶
Bases: StrEnum
Supported token sampling modes.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
39 40 41 42 43 44 | |
LayoutActionConfig ¶
Bases: PretrainedConfig
Architecture and tokenizer metadata for LayoutAction checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Dataset slug. |
'rico13'
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Dataset-local label mapping. |
None
|
precision
|
int
|
Coordinate precision; checkpoint defaults to 8 bits. |
8
|
max_elements
|
int | None
|
Maximum number of layout elements. |
None
|
block_size
|
int | None
|
GPT context length. Defaults to released max token length. |
None
|
vocab_size
|
int | None
|
Token vocabulary size. Defaults to the reference formula. |
None
|
n_layer
|
int
|
Number of GPT blocks. |
6
|
n_head
|
int
|
Attention heads. |
8
|
n_embd
|
int
|
Hidden size. |
512
|
embd_pdrop
|
float
|
Embedding dropout. |
0.1
|
resid_pdrop
|
float
|
Residual dropout. |
0.1
|
attn_pdrop
|
float
|
Attention dropout. |
0.1
|
default_sampling
|
LayoutActionSamplingMode | str
|
Default pipeline sampling mode. |
top_k
|
default_top_k
|
int
|
Default top-k value. |
5
|
default_temperature
|
float
|
Default sampling temperature. |
1.0
|
original_dataset_name
|
str | None
|
Original dataset name. |
None
|
original_asset_manifest
|
Mapping[str, str | int | list[str] | dict[str, AssetManifestFile]] | None
|
Optional asset manifest. |
None
|
kwargs
|
str | int | float | bool | None
|
Additional |
{}
|
Examples:
>>> config = LayoutActionConfig(dataset_name="publaynet")
>>> config.bos_token_id == config.vocab_size - 3
True
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
__init__ ¶
__init__(
*,
dataset_name: str = "rico13",
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
precision: int = 8,
max_elements: int | None = None,
block_size: int | None = None,
vocab_size: int | None = None,
n_layer: int = 6,
n_head: int = 8,
n_embd: int = 512,
embd_pdrop: float = 0.1,
resid_pdrop: float = 0.1,
attn_pdrop: float = 0.1,
default_sampling: LayoutActionSamplingMode
| str = LayoutActionSamplingMode.top_k,
default_top_k: int = 5,
default_temperature: float = 1.0,
original_dataset_name: str | None = None,
original_asset_manifest: Mapping[
str,
str
| int
| list[str]
| dict[str, AssetManifestFile],
]
| None = None,
model_type: str | None = None,
transformers_version: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize LayoutAction metadata and derived token ids.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
label_token_id ¶
label_token_id(label_id: int) -> int
Return the synthetic token id for a dataset-local label id.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
190 191 192 193 194 195 196 | |
label_id_from_token ¶
label_id_from_token(token_id: int) -> int | None
Return a dataset-local label id for a label token id.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
198 199 200 201 202 203 204 | |
object_token_id ¶
object_token_id(back_reference: int) -> int
Return the token id for a previous-object back reference.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
206 207 208 209 210 211 | |
back_reference_from_token ¶
back_reference_from_token(token_id: int) -> int | None
Return a previous-object back reference from a token id.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
213 214 215 216 217 218 | |
normalize_sampling_mode ¶
normalize_sampling_mode(
value: LayoutActionSamplingMode | str,
) -> LayoutActionSamplingMode
Normalize a sampling-mode value.
Source code in models/layout-action/src/layout_action/configuration_layout_action.py
47 48 49 50 51 52 53 54 55 56 | |
conversion ¶
Checkpoint conversion helpers for LayoutAction.
StateDictKeyReport
dataclass
¶
One source-to-target state-dict mapping result.
Source code in models/layout-action/src/layout_action/conversion.py
20 21 22 23 24 25 26 27 | |
StateDictKeyReportDict ¶
Bases: TypedDict
Serialized source-to-target state-dict mapping result.
Source code in models/layout-action/src/layout_action/conversion.py
30 31 32 33 34 35 36 | |
LayoutActionConversionReport ¶
Bases: TypedDict
Serialized LayoutAction conversion report.
Source code in models/layout-action/src/layout_action/conversion.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
remap_layout_action_key ¶
remap_layout_action_key(key: str) -> str
Map a vendor LayoutAction state-dict key to this package.
Source code in models/layout-action/src/layout_action/conversion.py
60 61 62 | |
remap_state_dict ¶
remap_state_dict(
state_dict: dict[str, Shaped[Tensor, "..."]],
model: LayoutActionForCausalLM,
) -> tuple[
dict[str, Shaped[torch.Tensor, "..."]],
list[StateDictKeyReport],
]
Remap and report checkpoint key coverage.
Source code in models/layout-action/src/layout_action/conversion.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
sha256_file ¶
sha256_file(path: str | Path) -> str
Return the SHA256 digest for a checkpoint file.
Source code in models/layout-action/src/layout_action/conversion.py
89 90 91 92 93 94 95 | |
convert_layout_action_checkpoint ¶
convert_layout_action_checkpoint(
*,
checkpoint: str | Path,
output_dir: str | Path,
config: LayoutActionConfig,
strict: bool = True,
) -> LayoutActionConversionReport
Convert a raw vendor .pth checkpoint to HF-style files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint
|
str | Path
|
Raw PyTorch state-dict path. |
required |
output_dir
|
str | Path
|
Destination checkpoint directory. |
required |
config
|
LayoutActionConfig
|
LayoutAction config built from dataset metadata. |
required |
strict
|
bool
|
Whether model loading is strict. |
True
|
Returns:
| Type | Description |
|---|---|
LayoutActionConversionReport
|
Conversion report dictionary. |
Source code in models/layout-action/src/layout_action/conversion.py
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 | |
data ¶
Dataset metadata for LayoutAction checkpoints.
LayoutActionDatasetName ¶
Bases: StrEnum
Dataset names supported by the LayoutAction package.
Source code in models/layout-action/src/layout_action/data.py
9 10 11 12 13 14 15 16 | |
normalize_vendor_dataset_name ¶
normalize_vendor_dataset_name(
dataset_name: str | LayoutActionDatasetName,
) -> str
Normalize public and release dataset aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str | LayoutActionDatasetName
|
Dataset name or alias. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Canonical package dataset name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset is unsupported. |
Examples:
>>> normalize_vendor_dataset_name("rico")
'rico13'
Source code in models/layout-action/src/layout_action/data.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
layout_action_labels ¶
layout_action_labels(
dataset_name: str | LayoutActionDatasetName,
) -> tuple[str, ...]
Return the exact label order used by the LayoutAction released assets.
Source code in models/layout-action/src/layout_action/data.py
77 78 79 80 81 82 83 84 85 86 87 88 | |
max_elements_for_layout_action_dataset ¶
max_elements_for_layout_action_dataset(
dataset_name: str | LayoutActionDatasetName,
) -> int
Return the released maximum element count for a LayoutAction dataset.
Source code in models/layout-action/src/layout_action/data.py
91 92 93 94 95 96 97 98 99 100 | |
iter_org_rico13_samples ¶
iter_org_rico13_samples() -> None
Placeholder for the org RICO adapter.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always, until the lightweight streaming adapter is wired without full dataset downloads. |
Source code in models/layout-action/src/layout_action/data.py
103 104 105 106 107 108 109 110 111 112 113 114 | |
iter_org_publaynet_samples ¶
iter_org_publaynet_samples() -> None
Placeholder for the org PubLayNet adapter.
Source code in models/layout-action/src/layout_action/data.py
117 118 119 120 121 122 | |
iter_vendor_infoppt_samples ¶
iter_vendor_infoppt_samples() -> None
Placeholder for original-distribution-only InfoPPT loading.
Source code in models/layout-action/src/layout_action/data.py
125 126 127 128 129 130 | |
generation_layout_action ¶
Token sampling helpers for LayoutAction.
TokenModelOutput ¶
Bases: Protocol
Model output carrying logits.
Source code in models/layout-action/src/layout_action/generation_layout_action.py
18 19 20 21 22 | |
ActionTokenModel ¶
Bases: Protocol
Minimal protocol implemented by LayoutAction token models.
Source code in models/layout-action/src/layout_action/generation_layout_action.py
25 26 27 28 29 30 31 32 33 34 35 | |
get_block_size ¶
get_block_size() -> int
Return the maximum context length.
Source code in models/layout-action/src/layout_action/generation_layout_action.py
29 30 | |
__call__ ¶
__call__(
input_ids: Int[Tensor, "batch sequence"],
) -> TokenModelOutput
Return a model output with logits.
Source code in models/layout-action/src/layout_action/generation_layout_action.py
32 33 34 35 | |
LayoutActionSamplingConfig
dataclass
¶
Sampling parameters for LayoutAction token generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
LayoutActionSamplingMode
|
Greedy, multinomial, or top-k sampling. |
top_k
|
temperature
|
float
|
Positive logit temperature. |
1.0
|
top_k
|
int | None
|
Optional top-k crop size. |
5
|
Examples:
>>> str(LayoutActionSamplingConfig().mode)
'top_k'
Source code in models/layout-action/src/layout_action/generation_layout_action.py
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 | |
from_values
classmethod
¶
from_values(
*,
mode: LayoutActionSamplingMode | str,
temperature: float,
top_k: int | None,
) -> "LayoutActionSamplingConfig"
Build a normalized sampling config from public values.
Source code in models/layout-action/src/layout_action/generation_layout_action.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
top_k_logits ¶
top_k_logits(
logits: Float[Tensor, "batch vocab"], k: int
) -> Float[torch.Tensor, "batch vocab"]
Mask logits outside the top k values exactly like the reference helper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Float[Tensor, 'batch vocab']
|
Logits shaped |
required |
k
|
int
|
Number of top logits to keep. |
required |
Returns:
| Type | Description |
|---|---|
Float[Tensor, 'batch vocab']
|
Logits with non-top-k entries set to negative infinity. |
Source code in models/layout-action/src/layout_action/generation_layout_action.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
sample_action_tokens ¶
sample_action_tokens(
model: ActionTokenModel,
input_ids: Int[Tensor, "batch sequence"],
*,
max_new_tokens: int,
sampling: LayoutActionSamplingConfig,
forced_token_ids: Int[Tensor, "batch new_tokens"]
| None = None,
generator: Generator | None = None,
) -> Int[torch.Tensor, "batch sequence"]
Autoregressively sample LayoutAction token ids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
ActionTokenModel
|
Token model returning logits. |
required |
input_ids
|
Int[Tensor, 'batch sequence']
|
Prompt ids shaped |
required |
max_new_tokens
|
int
|
Number of new tokens to append. |
required |
sampling
|
LayoutActionSamplingConfig
|
Sampling parameters. |
required |
forced_token_ids
|
Int[Tensor, 'batch new_tokens'] | None
|
Optional ids shaped |
None
|
generator
|
Generator | None
|
Optional torch generator for multinomial sampling. |
None
|
Returns:
| Type | Description |
|---|---|
Int[Tensor, 'batch sequence']
|
Prompt plus sampled token ids. |
Source code in models/layout-action/src/layout_action/generation_layout_action.py
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 | |
modeling_layout_action ¶
PyTorch model wrapper for LayoutAction.
LayoutActionCausalSelfAttention ¶
Bases: Module
Checkpoint-compatible masked multi-head self-attention.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
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 | |
__init__ ¶
__init__(
config: LayoutActionConfig,
mask: Float[Tensor, "1 1 block block"],
) -> None
Initialize key, query, value, and output projections.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
forward ¶
forward(
x: Float[Tensor, "batch sequence channels"],
) -> Float[torch.Tensor, "batch sequence channels"]
Apply causal self-attention.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
LayoutActionBlock ¶
Bases: Module
Checkpoint-compatible GPT block.
Source code in models/layout-action/src/layout_action/modeling_layout_action.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 | |
__init__ ¶
__init__(
config: LayoutActionConfig,
mask: Float[Tensor, "1 1 block block"],
) -> None
Initialize layer norms, self-attention, and MLP.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
forward ¶
forward(
x: Float[Tensor, "batch sequence channels"],
) -> Float[torch.Tensor, "batch sequence channels"]
Run one transformer block.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
82 83 84 85 86 87 | |
LayoutActionForCausalLM ¶
Bases: PreTrainedModel
Transformers PreTrainedModel for LayoutAction token prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutActionConfig
|
LayoutAction architecture and vocabulary metadata. |
required |
Examples:
>>> config = LayoutActionConfig(n_layer=1, n_head=2, n_embd=16, max_elements=1)
>>> model = LayoutActionForCausalLM(config)
>>> out = model(torch.tensor([[config.bos_token_id]]))
>>> out.logits.shape[-1] == config.vocab_size
True
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
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 | |
__init__ ¶
__init__(config: LayoutActionConfig) -> None
Initialize checkpoint-compatible GPT modules.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
get_block_size ¶
get_block_size() -> int
Return the maximum context length.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
127 128 129 | |
get_input_embeddings ¶
get_input_embeddings() -> nn.Embedding
Return token embeddings.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
131 132 133 | |
set_input_embeddings ¶
set_input_embeddings(value: Embedding) -> None
Replace token embeddings.
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
135 136 137 | |
forward ¶
forward(
input_ids: Int[Tensor, "batch sequence"],
attention_mask: Bool[Tensor, "batch sequence"]
| None = None,
labels: Int[Tensor, "batch sequence"] | None = None,
return_dict: bool | None = None,
output_hidden_states: bool | None = None,
output_attentions: bool | None = None,
) -> (
CausalLMOutputWithCrossAttentions
| tuple[Shaped[torch.Tensor, "..."], ...]
)
Run a standard causal language-model forward pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Int[Tensor, 'batch sequence']
|
Token ids shaped |
required |
attention_mask
|
Bool[Tensor, 'batch sequence'] | None
|
Accepted for Transformers compatibility; causal masking follows the checkpoint implementation. |
None
|
labels
|
Int[Tensor, 'batch sequence'] | None
|
Optional next-token labels. |
None
|
return_dict
|
bool | None
|
Whether to return a dataclass output. |
None
|
output_hidden_states
|
bool | None
|
Include final hidden states. |
None
|
output_attentions
|
bool | None
|
Accepted for API compatibility; attentions are not materialized by the checkpoint-compatible blocks. |
None
|
Returns:
| Type | Description |
|---|---|
CausalLMOutputWithCrossAttentions | tuple[Shaped[Tensor, '...'], ...]
|
Causal LM output or tuple. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sequence length exceeds |
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
generate ¶
generate(
input_ids: Int[Tensor, "batch sequence"],
*,
max_new_tokens: int,
temperature: float = 1.0,
top_k: int | None = None,
do_sample: bool = False,
forced_token_ids: Int[Tensor, "batch sequence"]
| None = None,
generator: Generator | None = None,
) -> Int[torch.Tensor, "batch sequence"]
Generate token ids with the reference sampling loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Int[Tensor, 'batch sequence']
|
Prompt token ids. |
required |
max_new_tokens
|
int
|
Number of new tokens. |
required |
temperature
|
float
|
Sampling temperature. |
1.0
|
top_k
|
int | None
|
Optional top-k crop size. |
None
|
do_sample
|
bool
|
Whether to use multinomial sampling. If |
False
|
forced_token_ids
|
Int[Tensor, 'batch sequence'] | None
|
Optional ids to force at each generation step. |
None
|
generator
|
Generator | None
|
Optional torch generator for multinomial sampling. |
None
|
Returns:
| Type | Description |
|---|---|
Int[Tensor, 'batch sequence']
|
Prompt plus generated token ids. |
Source code in models/layout-action/src/layout_action/modeling_layout_action.py
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 | |
pipeline_layout_action ¶
Pipeline wrapper for LayoutAction generation.
LayoutActionPipeline ¶
Bases: LayoutGenerationPipeline
Compose a LayoutAction model and processor for layout generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LayoutActionForCausalLM
|
Converted LayoutAction causal LM. |
required |
processor
|
LayoutActionProcessor
|
Matching processor/tokenizer. |
required |
config
|
LayoutActionConfig | None
|
Optional root pipeline config. Defaults to |
None
|
Examples:
>>> config = LayoutActionConfig(n_layer=1, n_head=2, n_embd=16, max_elements=1)
>>> pipe = LayoutActionPipeline(
... model=LayoutActionForCausalLM(config),
... processor=LayoutActionProcessor(LayoutActionTokenizer(config)),
... config=config,
... )
>>> pipe.config.model_type
'layout-action'
Source code in models/layout-action/src/layout_action/pipeline_layout_action.py
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 | |
__init__ ¶
__init__(
model: LayoutActionForCausalLM,
processor: LayoutActionProcessor,
config: LayoutActionConfig | None = None,
) -> None
Initialize the pipeline.
Source code in models/layout-action/src/layout_action/pipeline_layout_action.py
99 100 101 102 103 104 105 106 107 108 109 | |
__call__ ¶
__call__(
*,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.unconditional,
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| Sequence[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
num_inference_steps: int | None = None,
output_type: OutputType = "dataclass",
return_intermediates: bool = False,
sampling: Literal[
"greedy", "multinomial", "top_k"
] = "top_k",
temperature: float = 1.0,
top_k: int | None = 5,
) -> LayoutGenerationOutput | LayoutActionOutputDict
Generate a layout through the public LayoutAction interface.
Source code in models/layout-action/src/layout_action/pipeline_layout_action.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
processing_layout_action ¶
Processor for LayoutAction conditions and output decoding.
LayoutActionOutputDict ¶
Bases: TypedDict
Dictionary form of the LayoutAction public output.
Source code in models/layout-action/src/layout_action/processing_layout_action.py
27 28 29 30 31 32 33 34 35 | |
LayoutActionProcessor ¶
Bases: ProcessorMixin
Prepare LayoutAction prompts and decode generated action sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
LayoutActionTokenizer
|
LayoutAction tokenizer. |
required |
Examples:
>>> processor = LayoutActionProcessor(LayoutActionTokenizer(LayoutActionConfig(max_elements=1)))
>>> encoded = processor(condition_type="unconditional")
>>> encoded["input_ids"].shape
torch.Size([1, 1])
Source code in models/layout-action/src/layout_action/processing_layout_action.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 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 | |
__init__ ¶
__init__(tokenizer: LayoutActionTokenizer) -> None
Initialize the processor.
Source code in models/layout-action/src/layout_action/processing_layout_action.py
62 63 64 65 | |
__call__ ¶
__call__(
*,
condition_type: ConditionType
| str = ConditionType.unconditional,
bbox: Float[Tensor, "batch elements 4"]
| Float[ndarray, "batch elements 4"]
| Sequence[ArrayLikeInput]
| None = None,
labels: Int[Tensor, "batch elements"]
| Int[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
mask: Bool[Tensor, "batch elements"]
| Bool[ndarray, "batch elements"]
| Sequence[ArrayLikeInput]
| None = None,
num_elements: int
| list[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
batch_size: int = 1,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Encode a public generation condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str
|
Canonical condition or supported release alias. |
unconditional
|
bbox
|
Float[Tensor, 'batch elements 4'] | Float[ndarray, 'batch elements 4'] | Sequence[ArrayLikeInput] | None
|
Optional public boxes for completion prompts. |
None
|
labels
|
Int[Tensor, 'batch elements'] | Int[ndarray, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional labels for label/completion prompts. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Bool[ndarray, 'batch elements'] | Sequence[ArrayLikeInput] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | list[int] | Int[Tensor, 'batch'] | None
|
Optional element count or completion prefix length. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Canvas size for pixel boxes. |
None
|
batch_size
|
int
|
Batch size for unconditional generation. |
1
|
return_tensors
|
Literal['pt']
|
Tensor framework. Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding with prompt ids and optional forced token ids. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the condition is unsupported by LayoutAction. |
ValueError
|
If required condition payloads are missing. |
Source code in models/layout-action/src/layout_action/processing_layout_action.py
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 | |
post_process_layouts ¶
post_process_layouts(
sequences: Int[Tensor, "batch tokens"],
*,
output_type: OutputType = "dataclass",
return_intermediates: bool = False,
) -> LayoutGenerationOutput | LayoutActionOutputDict
Decode generated sequences to the common output schema.
Source code in models/layout-action/src/layout_action/processing_layout_action.py
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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
push_to_hub: bool = False,
**kwargs: str | int | float | bool | None,
) -> None
Save processor and tokenizer metadata.
Source code in models/layout-action/src/layout_action/processing_layout_action.py
233 234 235 236 237 238 239 240 241 242 243 244 245 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | PathLike[str],
cache_dir: str | PathLike[str] | None = None,
force_download: bool = False,
local_files_only: bool = False,
token: str | bool | None = None,
revision: str = "main",
**kwargs: str | int | float | bool | None,
) -> "LayoutActionProcessor"
Load processor metadata from a checkpoint directory or Hub repo id.
Source code in models/layout-action/src/layout_action/processing_layout_action.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
tokenization_layout_action ¶
Synthetic action-token tokenizer for LayoutAction.
DecodedActions ¶
Bases: TypedDict
Decoded action-token details.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
20 21 22 23 24 25 | |
LayoutActionTokenizer ¶
Bases: PreTrainedTokenizer
PreTrainedTokenizer for LayoutAction's 13-token element grammar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayoutActionConfig | None
|
LayoutAction config carrying vocabulary metadata. |
None
|
tokenizer_config_file
|
str | None
|
Optional saved tokenizer metadata path. |
None
|
kwargs
|
str | int | float | bool | None
|
Standard tokenizer keyword arguments. |
{}
|
Examples:
>>> tokenizer = LayoutActionTokenizer(LayoutActionConfig(max_elements=2))
>>> tokenizer.bos_token_id == tokenizer.config.bos_token_id
True
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
__init__ ¶
__init__(
config: LayoutActionConfig | None = None,
tokenizer_config_file: str | None = None,
**kwargs: str | int | float | bool | None,
) -> None
Initialize synthetic token strings.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
get_vocab ¶
get_vocab() -> dict[str, int]
Return synthetic token strings mapped to ids.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
94 95 96 | |
convert_tokens_to_string ¶
convert_tokens_to_string(tokens: list[str]) -> str
Join synthetic layout tokens.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
110 111 112 | |
save_vocabulary ¶
save_vocabulary(
save_directory: str | PathLike[str],
filename_prefix: str | None = None,
) -> tuple[str, ...]
Save tokenizer metadata.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | PathLike[str],
*inputs: str,
cache_dir: str | PathLike[str] | None = None,
force_download: bool = False,
local_files_only: bool = False,
token: str | bool | None = None,
revision: str = "main",
**kwargs: str | int | float | bool | None,
) -> "LayoutActionTokenizer"
Load tokenizer metadata through the standard Transformers resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Local tokenizer directory or Hub repo id. |
required |
inputs
|
str
|
Reserved tokenizer inputs. |
()
|
cache_dir
|
str | PathLike[str] | None
|
Cache directory for Hub-backed files. |
None
|
force_download
|
bool
|
Whether to refresh cached files. |
False
|
local_files_only
|
bool
|
Whether to disable network resolution. |
False
|
token
|
str | bool | None
|
Hugging Face token. |
None
|
revision
|
str
|
Hub revision. |
'main'
|
kwargs
|
str | int | float | bool | None
|
Standard tokenizer keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
'LayoutActionTokenizer'
|
Loaded LayoutAction tokenizer. |
Source code in models/layout-action/src/layout_action/tokenization_layout_action.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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
quantize_bbox ¶
quantize_bbox(
bbox: Float[Tensor, "... 4"],
) -> Int[torch.Tensor, "... 4"]
Quantize normalized center xywh boxes with checkpoint binning.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
179 180 181 182 183 184 185 186 187 188 189 | |
continuize_bbox ¶
continuize_bbox(
quantized_bbox: Int[Tensor, "... 4"],
) -> Float[torch.Tensor, "... 4"]
Decode quantized boxes to normalized center xywh values.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
191 192 193 194 195 196 197 | |
encode_layout ¶
encode_layout(
*,
bbox: Float[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
) -> Int[torch.Tensor, "batch tokens"]
Encode public normalized layouts to padded action-token sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Float[Tensor, 'batch elements 4']
|
Normalized center |
required |
labels
|
Int[Tensor, 'batch elements']
|
Dataset-local labels shaped |
required |
mask
|
Bool[Tensor, 'batch elements']
|
Valid-element mask shaped |
required |
Returns:
| Type | Description |
|---|---|
Int[Tensor, 'batch tokens']
|
Token ids shaped |
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
encode_action_layout ¶
encode_action_layout(
*,
quantized_bbox: Int[Tensor, "batch elements 4"],
labels: Int[Tensor, "batch elements"],
mask: Bool[Tensor, "batch elements"],
) -> Int[torch.Tensor, "batch tokens"]
Encode already quantized boxes to action tokens.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
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 | |
decode_layout ¶
decode_layout(
input_ids: Int[Tensor, "batch_or_tokens ..."],
) -> dict[str, Shaped[torch.Tensor, "..."]]
Decode action-token sequences to public layout tensors.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
337 338 339 340 341 342 343 344 | |
decode_action_tokens ¶
decode_action_tokens(
input_ids: Int[Tensor, "batch_or_tokens ..."],
*,
return_actions: bool = False,
) -> dict[
str,
Shaped[torch.Tensor, "..."]
| dict[str, Shaped[torch.Tensor, "..."]],
]
Decode action tokens and optionally return raw action details.
Source code in models/layout-action/src/layout_action/tokenization_layout_action.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |