Posterllama
PosterLlama processor, parser, and layout-generation pipeline.
PosterLlamaConfig ¶
Bases: PretrainedConfig
Configuration for local PosterLlama recipe artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_repo_id
|
str
|
Source Hub repository containing the raw checkpoint. |
'poong/PosterLlama'
|
base_llm_repo_id
|
str
|
Preferred CodeLLaMA/LLaMA backbone repository id. |
'codellama/CodeLlama-7b-hf'
|
alternate_base_llm_repo_ids
|
Sequence[str]
|
Alternate backbone ids recorded for audit. |
('meta-llama/Llama-2-7b-chat-hf',)
|
vision_encoder_repo_id
|
str
|
Vision encoder repository id. |
'facebook/dinov2-base'
|
vision_model_name
|
PosterLlamaVisionModelName
|
Original vision tower selector. |
'dino_v2'
|
lora_r
|
int
|
LoRA rank used by the released recipe. |
64
|
lora_alpha
|
int
|
LoRA alpha used by the released recipe. |
16
|
lora_dropout
|
float
|
LoRA dropout used by the released recipe. |
0.05
|
lora_target_modules
|
Sequence[str]
|
LLM projection module names targeted by LoRA. |
('q_proj', 'v_proj')
|
prompt_template
|
str
|
Wrapper applied around generated layout prompts. |
'{}'
|
image_placeholder
|
str
|
Placeholder token used for image feature insertion. |
'<ImageHere>'
|
image_end_token
|
str
|
End marker for image features. |
'</Img>'
|
max_txt_len
|
int
|
Original maximum text length. |
400
|
max_context_len
|
int
|
Original context length budget. |
3800
|
default_max_new_tokens
|
int
|
Default generation budget. |
1024
|
default_do_sample
|
bool
|
Default sampled-generation flag. |
True
|
default_temperature
|
float
|
Default generation temperature. |
0.6
|
default_top_p
|
float
|
Default nucleus sampling value. |
0.9
|
default_top_k
|
int
|
Default top-k sampling value. |
40
|
default_num_beams
|
int
|
Default beam count. |
4
|
dataset_name
|
PosterLlamaDatasetName
|
Poster dataset key. |
'cgl'
|
id2label
|
Mapping[int | str, str] | None
|
Dataset-local label vocabulary. |
None
|
canvas_size
|
tuple[int, int] | list[int] | None
|
Optional default canvas size as |
None
|
checkpoint_license_status
|
PosterLlamaLicenseStatus
|
Redistribution status for converted weights. |
'unverified'
|
processor_subfolder
|
str
|
Pipeline processor subfolder. |
'processor'
|
runtime_subfolder
|
str
|
Optional converted runtime subfolder. |
'runtime'
|
kwargs
|
PosterLlamaConfigValue
|
Extra |
{}
|
Examples:
>>> cfg = PosterLlamaConfig(canvas_size=(360, 504))
>>> cfg.id2label[1]
'text'
Source code in models/posterllama/src/posterllama/configuration_posterllama.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
__init__ ¶
__init__(
checkpoint_repo_id: str = "poong/PosterLlama",
base_llm_repo_id: str = "codellama/CodeLlama-7b-hf",
alternate_base_llm_repo_ids: Sequence[str] = (
"meta-llama/Llama-2-7b-chat-hf",
),
vision_encoder_repo_id: str = "facebook/dinov2-base",
vision_model_name: PosterLlamaVisionModelName = "dino_v2",
lora_r: int = 64,
lora_alpha: int = 16,
lora_dropout: float = 0.05,
lora_target_modules: Sequence[str] = (
"q_proj",
"v_proj",
),
prompt_template: str = "{}",
image_placeholder: str = "<ImageHere>",
image_end_token: str = "</Img>",
max_txt_len: int = 400,
max_context_len: int = 3800,
default_max_new_tokens: int = 1024,
default_do_sample: bool = True,
default_temperature: float = 0.6,
default_top_p: float = 0.9,
default_top_k: int = 40,
default_num_beams: int = 4,
dataset_name: PosterLlamaDatasetName = "cgl",
id2label: Mapping[int | str, str] | None = None,
canvas_size: tuple[int, int] | list[int] | None = None,
checkpoint_license_status: PosterLlamaLicenseStatus = "unverified",
processor_subfolder: str = "processor",
runtime_subfolder: str = "runtime",
**kwargs: PosterLlamaConfigValue,
) -> None
Initialize configuration values.
Source code in models/posterllama/src/posterllama/configuration_posterllama.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 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 | |
PosterLlamaImageProcessor ¶
Bases: BaseImageProcessor
Prepare RGB images for PosterLlama smoke and recipe paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_size
|
tuple[int, int] | None
|
Optional |
None
|
vision_encoder_repo_id
|
str
|
Vision encoder id recorded with the processor. |
'facebook/dinov2-base'
|
Examples:
>>> processor = PosterLlamaImageProcessor(image_size=(8, 8))
>>> out = processor.preprocess(torch.zeros(3, 8, 8))
>>> tuple(out["pixel_values"].shape)
(1, 3, 8, 8)
Source code in models/posterllama/src/posterllama/image_processing_posterllama.py
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 | |
__init__ ¶
__init__(
image_size: tuple[int, int] | None = None,
vision_encoder_repo_id: str = "facebook/dinov2-base",
**kwargs: PosterLlamaImageProcessorKwarg,
) -> None
Initialize image processor metadata.
Source code in models/posterllama/src/posterllama/image_processing_posterllama.py
83 84 85 86 87 88 89 90 91 92 | |
preprocess ¶
preprocess(
images: ImageInput | Sequence[ImageInput] | None,
return_tensors: Literal["pt"] = "pt",
**kwargs: PosterLlamaImageProcessorKwarg,
) -> BatchFeature
Convert images to tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | Sequence[ImageInput] | None
|
PIL, NumPy, or torch image inputs. Omitted images create a zero placeholder for parser-only smoke calls. |
required |
return_tensors
|
Literal['pt']
|
Tensor return format. Only |
'pt'
|
kwargs
|
PosterLlamaImageProcessorKwarg
|
Reserved image-processing options. |
{}
|
Returns:
| Type | Description |
|---|---|
BatchFeature
|
BatchFeature containing |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in models/posterllama/src/posterllama/image_processing_posterllama.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
to_dict ¶
to_dict() -> dict[str, str | tuple[int, int] | None]
Serialize image processor metadata.
Source code in models/posterllama/src/posterllama/image_processing_posterllama.py
131 132 133 134 135 136 | |
PosterLlamaPipeline ¶
Bases: LayoutGenerationPipeline
Compose a PosterLlama processor and converted runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PosterLlamaConfig
|
Explicit pipeline configuration. |
required |
processor
|
PosterLlamaProcessor
|
Explicit processor. |
required |
runtime
|
PosterLlamaRuntime | None
|
Optional converted runtime. Parser-only saved artifacts may omit it. |
None
|
Examples:
>>> cfg = PosterLlamaConfig(canvas_size=(100, 100))
>>> text = '<svg width="100" height="100"><rect data-category="text" x="0" y="0" width="10" height="10"/></svg>'
>>> pipe = PosterLlamaPipeline(
... config=cfg,
... processor=PosterLlamaProcessor.from_config(cfg),
... runtime=PosterLlamaRuntime(text),
... )
>>> pipe(images=None).bbox.shape
torch.Size([1, 1, 4])
Source code in models/posterllama/src/posterllama/pipeline_posterllama.py
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 | |
__init__ ¶
__init__(
*,
config: PosterLlamaConfig,
processor: PosterLlamaProcessor,
runtime: PosterLlamaRuntime | None = None,
) -> None
Initialize pipeline components.
Source code in models/posterllama/src/posterllama/pipeline_posterllama.py
92 93 94 95 96 97 98 99 100 101 102 103 | |
__call__ ¶
__call__(
*,
images: ImageInput | Sequence[ImageInput] | None = None,
prompt: str | Sequence[str] | None = None,
content: Mapping[str, str | int | float | bool | None]
| Sequence[
Mapping[str, str | int | float | bool | None]
]
| None = None,
texts: str
| Sequence[str]
| Sequence[Sequence[str]]
| None = None,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.content_image,
labels: Int[Tensor, "..."]
| Sequence[Sequence[int | str]]
| Sequence[int | str]
| None = None,
bbox: Float[Tensor, "..."]
| Sequence[Sequence[Sequence[float | int]]]
| Sequence[Sequence[float | int]]
| Sequence[float | int]
| None = None,
mask: Bool[Tensor, "..."]
| Sequence[Sequence[bool]]
| Sequence[bool]
| None = None,
num_elements: int
| Sequence[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: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
max_new_tokens: int | None = None,
do_sample: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
top_k: int | None = None,
num_beams: int | None = None,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| dict[int, str]
| Mapping[
str, str | bytes | int | float | bool | None
]
| list[str]
| list[tuple[float, float, float, float]]
| tuple[int, int]
| str
| bytes
| int
| float
| bool
| None,
]
)
Generate a poster layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | Sequence[ImageInput] | None
|
Poster image inputs. |
None
|
prompt
|
str | Sequence[str] | None
|
Optional prompt prefix override. |
None
|
content
|
Mapping[str, str | int | float | bool | None] | Sequence[Mapping[str, str | int | float | bool | None]] | None
|
Optional content metadata. |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional poster text strings. |
None
|
batch_size
|
int
|
Batch size when images are omitted. |
1
|
seed
|
int | None
|
Convenience seed used only when |
None
|
generator
|
Generator | None
|
Explicit PyTorch generator; takes precedence over |
None
|
condition_type
|
ConditionType | str
|
Canonical condition or PosterLlama release alias. |
content_image
|
labels
|
Int[Tensor, '...'] | Sequence[Sequence[int | str]] | Sequence[int | str] | None
|
Optional label constraints. |
None
|
bbox
|
Float[Tensor, '...'] | Sequence[Sequence[Sequence[float | int]]] | Sequence[Sequence[float | int]] | Sequence[float | int] | None
|
Optional box constraints. |
None
|
mask
|
Bool[Tensor, '...'] | Sequence[Sequence[bool]] | Sequence[bool] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | Sequence[int] | Int[Tensor, 'batch'] | None
|
Optional requested element count. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Canvas size as |
None
|
num_inference_steps
|
int | None
|
Reserved shared argument. |
None
|
output_type
|
Literal['dataclass', 'dict']
|
|
'dataclass'
|
return_intermediates
|
bool
|
Whether to include prompt and parse diagnostics. |
False
|
max_new_tokens
|
int | None
|
Generation token budget. |
None
|
do_sample
|
bool | None
|
Sampling flag. |
None
|
temperature
|
float | None
|
Sampling temperature. |
None
|
top_p
|
float | None
|
Nucleus sampling value. |
None
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
num_beams
|
int | None
|
Beam count. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | dict[int, str] | Mapping[str, str | bytes | int | float | bool | None] | list[str] | list[tuple[float, float, float, float]] | tuple[int, int] | str | bytes | int | float | bool | None]
|
LayoutGenerationOutput or dictionary. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If converted runtime assets are absent. |
Source code in models/posterllama/src/posterllama/pipeline_posterllama.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 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 | |
PosterLlamaProcessor ¶
Bases: ProcessorMixin
Build PosterLlama prompts and decode generated HTML/SVG layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_processor
|
PosterLlamaImageProcessor
|
Image processor metadata wrapper. |
required |
config
|
PosterLlamaConfig
|
Explicit PosterLlama configuration. |
required |
Examples:
>>> processor = PosterLlamaProcessor.from_config(PosterLlamaConfig())
>>> "Generate poster layout" in processor.build_prompt(condition_type="unconditional")
True
Source code in models/posterllama/src/posterllama/processing_posterllama.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |
__init__ ¶
__init__(
image_processor: PosterLlamaImageProcessor,
config: PosterLlamaConfig,
) -> None
Initialize processor components.
Source code in models/posterllama/src/posterllama/processing_posterllama.py
108 109 110 111 112 113 114 115 116 | |
from_config
classmethod
¶
from_config(
config: PosterLlamaConfig,
) -> "PosterLlamaProcessor"
Create a processor from an explicit config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PosterLlamaConfig
|
Processor configuration. |
required |
Returns:
| Type | Description |
|---|---|
'PosterLlamaProcessor'
|
PosterLlamaProcessor instance. |
Examples:
>>> PosterLlamaProcessor.from_config(PosterLlamaConfig()).config.model_type
'posterllama'
Source code in models/posterllama/src/posterllama/processing_posterllama.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
push_to_hub: bool = False,
**kwargs: str | int | float | bool | None,
) -> None
Save processor metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | PathLike[str]
|
Directory to write. |
required |
push_to_hub
|
bool
|
Accepted for ProcessorMixin compatibility; ignored. |
False
|
kwargs
|
str | int | float | bool | None
|
Accepted for ProcessorMixin compatibility; ignored. |
{}
|
Source code in models/posterllama/src/posterllama/processing_posterllama.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 | |
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",
*,
subfolder: str | None = None,
**kwargs: PosterLlamaImageProcessorKwarg,
) -> "PosterLlamaProcessor"
Load processor metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Checkpoint root or processor folder. |
required |
cache_dir
|
str | PathLike[str] | None
|
Accepted for ProcessorMixin compatibility. |
None
|
force_download
|
bool
|
Accepted for ProcessorMixin compatibility. |
False
|
local_files_only
|
bool
|
Whether to avoid network access. |
False
|
token
|
str | bool | None
|
Accepted for ProcessorMixin compatibility. |
None
|
revision
|
str
|
Accepted for ProcessorMixin compatibility. |
'main'
|
subfolder
|
str | None
|
Optional processor subfolder. |
None
|
kwargs
|
PosterLlamaImageProcessorKwarg
|
Accepted for ProcessorMixin compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
'PosterLlamaProcessor'
|
Loaded PosterLlamaProcessor. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |
normalize_condition_type ¶
normalize_condition_type(
condition_type: ConditionType | str,
) -> ConditionType
Normalize PosterLlama condition aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str
|
Canonical condition or PosterLlama release alias. |
required |
Returns:
| Type | Description |
|---|---|
ConditionType
|
Supported canonical condition. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the condition is known but unsupported. |
ValueError
|
If the condition is unknown. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |
__call__ ¶
__call__(
*,
images: ImageInput | Sequence[ImageInput] | None = None,
prompt: str | Sequence[str] | None = None,
content: Mapping[str, str | int | float | bool | None]
| Sequence[
Mapping[str, str | int | float | bool | None]
]
| None = None,
texts: str
| Sequence[str]
| Sequence[Sequence[str]]
| None = None,
batch_size: int = 1,
condition_type: ConditionType
| str = ConditionType.content_image,
labels: Int[Tensor, "..."]
| Sequence[Sequence[int | str]]
| Sequence[int | str]
| None = None,
bbox: Float[Tensor, "..."]
| Sequence[Sequence[Sequence[float | int]]]
| Sequence[Sequence[float | int]]
| Sequence[float | int]
| None = None,
mask: Bool[Tensor, "..."]
| Sequence[Sequence[bool]]
| Sequence[bool]
| None = None,
num_elements: int
| Sequence[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Encode public inputs into recipe prompt and image tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | Sequence[ImageInput] | None
|
Poster image inputs. |
None
|
prompt
|
str | Sequence[str] | None
|
Optional user-provided prompt text. |
None
|
content
|
Mapping[str, str | int | float | bool | None] | Sequence[Mapping[str, str | int | float | bool | None]] | None
|
Optional content metadata. |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional poster text strings. |
None
|
batch_size
|
int
|
Batch size when no images are supplied. |
1
|
condition_type
|
ConditionType | str
|
Canonical condition or PosterLlama release alias. |
content_image
|
labels
|
Int[Tensor, '...'] | Sequence[Sequence[int | str]] | Sequence[int | str] | None
|
Optional element label constraints. |
None
|
bbox
|
Float[Tensor, '...'] | Sequence[Sequence[Sequence[float | int]]] | Sequence[Sequence[float | int]] | Sequence[float | int] | None
|
Optional element boxes. |
None
|
mask
|
Bool[Tensor, '...'] | Sequence[Sequence[bool]] | Sequence[bool] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | Sequence[int] | Int[Tensor, 'batch'] | None
|
Optional requested element count. |
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 and prompt rendering. |
None
|
return_tensors
|
Literal['pt']
|
Tensor return format. Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
BatchEncoding containing prompt strings and tensors. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |
build_prompt ¶
build_prompt(
*,
condition_type: ConditionType
| str = ConditionType.content_image,
prompt: str | Sequence[str] | None = None,
content: Mapping[str, str | int | float | bool | None]
| Sequence[
Mapping[str, str | int | float | bool | None]
]
| None = None,
texts: str
| Sequence[str]
| Sequence[Sequence[str]]
| None = None,
labels: Int[Tensor, "..."]
| Sequence[Sequence[int | str]]
| Sequence[int | str]
| None = None,
bbox: Float[Tensor, "..."]
| Sequence[Sequence[Sequence[float | int]]]
| Sequence[Sequence[float | int]]
| Sequence[float | int]
| None = None,
mask: Bool[Tensor, "..."]
| Sequence[Sequence[bool]]
| Sequence[bool]
| None = None,
num_elements: int
| Sequence[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
) -> str | list[str]
Build a deterministic PosterLlama HTML prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str
|
Canonical condition or PosterLlama release alias. |
content_image
|
prompt
|
str | Sequence[str] | None
|
Optional prompt prefix override. |
None
|
content
|
Mapping[str, str | int | float | bool | None] | Sequence[Mapping[str, str | int | float | bool | None]] | None
|
Optional content metadata included in diagnostics text. |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional poster text strings. |
None
|
labels
|
Int[Tensor, '...'] | Sequence[Sequence[int | str]] | Sequence[int | str] | None
|
Optional label constraints. |
None
|
bbox
|
Float[Tensor, '...'] | Sequence[Sequence[Sequence[float | int]]] | Sequence[Sequence[float | int]] | Sequence[float | int] | None
|
Optional box constraints. |
None
|
mask
|
Bool[Tensor, '...'] | Sequence[Sequence[bool]] | Sequence[bool] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | Sequence[int] | Int[Tensor, 'batch'] | None
|
Requested element count for unconstrained slots. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Canvas size as |
None
|
Returns:
| Type | Description |
|---|---|
str | list[str]
|
Prompt string or list of prompt strings. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |
parse_output ¶
parse_output(
text: str,
*,
canvas_size: tuple[int, int] | None = None,
output_type: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
strict: bool = False,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| dict[int, str]
| list[str]
| list[tuple[float, float, float, float]]
| tuple[int, int]
| str
| int
| float
| bool
| None,
]
)
Parse generated HTML/SVG into public layout output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Generated markup. |
required |
canvas_size
|
tuple[int, int] | None
|
Canvas size override. |
None
|
output_type
|
Literal['dataclass', 'dict']
|
Return dataclass or dictionary. |
'dataclass'
|
return_intermediates
|
bool
|
Whether to include parse diagnostics. |
False
|
strict
|
bool
|
Whether malformed rectangles raise. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | dict[int, str] | list[str] | list[tuple[float, float, float, float]] | tuple[int, int] | str | int | float | bool | None]
|
LayoutGenerationOutput or dictionary. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |
configuration_posterllama ¶
Configuration for PosterLlama inference recipes.
PosterLlamaConfig ¶
Bases: PretrainedConfig
Configuration for local PosterLlama recipe artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_repo_id
|
str
|
Source Hub repository containing the raw checkpoint. |
'poong/PosterLlama'
|
base_llm_repo_id
|
str
|
Preferred CodeLLaMA/LLaMA backbone repository id. |
'codellama/CodeLlama-7b-hf'
|
alternate_base_llm_repo_ids
|
Sequence[str]
|
Alternate backbone ids recorded for audit. |
('meta-llama/Llama-2-7b-chat-hf',)
|
vision_encoder_repo_id
|
str
|
Vision encoder repository id. |
'facebook/dinov2-base'
|
vision_model_name
|
PosterLlamaVisionModelName
|
Original vision tower selector. |
'dino_v2'
|
lora_r
|
int
|
LoRA rank used by the released recipe. |
64
|
lora_alpha
|
int
|
LoRA alpha used by the released recipe. |
16
|
lora_dropout
|
float
|
LoRA dropout used by the released recipe. |
0.05
|
lora_target_modules
|
Sequence[str]
|
LLM projection module names targeted by LoRA. |
('q_proj', 'v_proj')
|
prompt_template
|
str
|
Wrapper applied around generated layout prompts. |
'{}'
|
image_placeholder
|
str
|
Placeholder token used for image feature insertion. |
'<ImageHere>'
|
image_end_token
|
str
|
End marker for image features. |
'</Img>'
|
max_txt_len
|
int
|
Original maximum text length. |
400
|
max_context_len
|
int
|
Original context length budget. |
3800
|
default_max_new_tokens
|
int
|
Default generation budget. |
1024
|
default_do_sample
|
bool
|
Default sampled-generation flag. |
True
|
default_temperature
|
float
|
Default generation temperature. |
0.6
|
default_top_p
|
float
|
Default nucleus sampling value. |
0.9
|
default_top_k
|
int
|
Default top-k sampling value. |
40
|
default_num_beams
|
int
|
Default beam count. |
4
|
dataset_name
|
PosterLlamaDatasetName
|
Poster dataset key. |
'cgl'
|
id2label
|
Mapping[int | str, str] | None
|
Dataset-local label vocabulary. |
None
|
canvas_size
|
tuple[int, int] | list[int] | None
|
Optional default canvas size as |
None
|
checkpoint_license_status
|
PosterLlamaLicenseStatus
|
Redistribution status for converted weights. |
'unverified'
|
processor_subfolder
|
str
|
Pipeline processor subfolder. |
'processor'
|
runtime_subfolder
|
str
|
Optional converted runtime subfolder. |
'runtime'
|
kwargs
|
PosterLlamaConfigValue
|
Extra |
{}
|
Examples:
>>> cfg = PosterLlamaConfig(canvas_size=(360, 504))
>>> cfg.id2label[1]
'text'
Source code in models/posterllama/src/posterllama/configuration_posterllama.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
__init__ ¶
__init__(
checkpoint_repo_id: str = "poong/PosterLlama",
base_llm_repo_id: str = "codellama/CodeLlama-7b-hf",
alternate_base_llm_repo_ids: Sequence[str] = (
"meta-llama/Llama-2-7b-chat-hf",
),
vision_encoder_repo_id: str = "facebook/dinov2-base",
vision_model_name: PosterLlamaVisionModelName = "dino_v2",
lora_r: int = 64,
lora_alpha: int = 16,
lora_dropout: float = 0.05,
lora_target_modules: Sequence[str] = (
"q_proj",
"v_proj",
),
prompt_template: str = "{}",
image_placeholder: str = "<ImageHere>",
image_end_token: str = "</Img>",
max_txt_len: int = 400,
max_context_len: int = 3800,
default_max_new_tokens: int = 1024,
default_do_sample: bool = True,
default_temperature: float = 0.6,
default_top_p: float = 0.9,
default_top_k: int = 40,
default_num_beams: int = 4,
dataset_name: PosterLlamaDatasetName = "cgl",
id2label: Mapping[int | str, str] | None = None,
canvas_size: tuple[int, int] | list[int] | None = None,
checkpoint_license_status: PosterLlamaLicenseStatus = "unverified",
processor_subfolder: str = "processor",
runtime_subfolder: str = "runtime",
**kwargs: PosterLlamaConfigValue,
) -> None
Initialize configuration values.
Source code in models/posterllama/src/posterllama/configuration_posterllama.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 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 | |
image_processing_posterllama ¶
Image processor metadata wrapper for PosterLlama recipes.
PosterLlamaImageProcessor ¶
Bases: BaseImageProcessor
Prepare RGB images for PosterLlama smoke and recipe paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_size
|
tuple[int, int] | None
|
Optional |
None
|
vision_encoder_repo_id
|
str
|
Vision encoder id recorded with the processor. |
'facebook/dinov2-base'
|
Examples:
>>> processor = PosterLlamaImageProcessor(image_size=(8, 8))
>>> out = processor.preprocess(torch.zeros(3, 8, 8))
>>> tuple(out["pixel_values"].shape)
(1, 3, 8, 8)
Source code in models/posterllama/src/posterllama/image_processing_posterllama.py
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 | |
__init__ ¶
__init__(
image_size: tuple[int, int] | None = None,
vision_encoder_repo_id: str = "facebook/dinov2-base",
**kwargs: PosterLlamaImageProcessorKwarg,
) -> None
Initialize image processor metadata.
Source code in models/posterllama/src/posterllama/image_processing_posterllama.py
83 84 85 86 87 88 89 90 91 92 | |
preprocess ¶
preprocess(
images: ImageInput | Sequence[ImageInput] | None,
return_tensors: Literal["pt"] = "pt",
**kwargs: PosterLlamaImageProcessorKwarg,
) -> BatchFeature
Convert images to tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | Sequence[ImageInput] | None
|
PIL, NumPy, or torch image inputs. Omitted images create a zero placeholder for parser-only smoke calls. |
required |
return_tensors
|
Literal['pt']
|
Tensor return format. Only |
'pt'
|
kwargs
|
PosterLlamaImageProcessorKwarg
|
Reserved image-processing options. |
{}
|
Returns:
| Type | Description |
|---|---|
BatchFeature
|
BatchFeature containing |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in models/posterllama/src/posterllama/image_processing_posterllama.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
to_dict ¶
to_dict() -> dict[str, str | tuple[int, int] | None]
Serialize image processor metadata.
Source code in models/posterllama/src/posterllama/image_processing_posterllama.py
131 132 133 134 135 136 | |
model_card ¶
Model-card metadata for PosterLlama recipe artifacts.
model_card_metadata ¶
model_card_metadata(
config: PosterLlamaConfig, *, hub_id: str
) -> dict[str, str | list[str]]
Return model-card metadata for a PosterLlama recipe artifact.
Source code in models/posterllama/src/posterllama/model_card.py
8 9 10 11 12 13 14 15 16 17 18 19 | |
modeling_posterllama ¶
Runtime adapter interfaces for converted PosterLlama components.
PosterLlamaRuntime ¶
Bases: Module
Minimal runtime interface used by PosterLlamaPipeline.
The full MiniGPT/DINO/CodeLLaMA stack is created by local conversion tools. This lightweight adapter keeps the public package importable in ordinary CI and gives tests a serializable runtime shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generated_text
|
str | None
|
Optional deterministic text emitted by this runtime. |
None
|
Examples:
>>> runtime = PosterLlamaRuntime('<svg width="1" height="1"></svg>')
>>> runtime.generate_texts(["prompt"])
['<svg width="1" height="1"></svg>']
Source code in models/posterllama/src/posterllama/modeling_posterllama.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 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 | |
__init__ ¶
__init__(generated_text: str | None = None) -> None
Initialize deterministic runtime metadata.
Source code in models/posterllama/src/posterllama/modeling_posterllama.py
30 31 32 33 | |
generate_texts ¶
generate_texts(
prompts: Sequence[str],
*,
pixel_values: Float[
Tensor, "batch channels height width"
]
| None = None,
generator: Generator | None = None,
max_new_tokens: int = 1024,
do_sample: bool = False,
temperature: float = 1.0,
top_p: float = 0.9,
top_k: int | None = None,
num_beams: int = 1,
) -> list[str]
Generate markup text for prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompts
|
Sequence[str]
|
Prompt strings. |
required |
pixel_values
|
Float[Tensor, 'batch channels height width'] | None
|
Optional image tensors. |
None
|
generator
|
Generator | None
|
Optional PyTorch generator. |
None
|
max_new_tokens
|
int
|
Generation length budget. |
1024
|
do_sample
|
bool
|
Sampling flag. |
False
|
temperature
|
float
|
Sampling temperature. |
1.0
|
top_p
|
float
|
Nucleus sampling value. |
0.9
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
num_beams
|
int
|
Beam count. |
1
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Generated markup strings. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no converted runtime text generator is available. |
Source code in models/posterllama/src/posterllama/modeling_posterllama.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
*,
is_main_process: bool = True,
) -> None
Save runtime metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | PathLike[str]
|
Directory to write. |
required |
is_main_process
|
bool
|
Whether this process should write files. |
True
|
Source code in models/posterllama/src/posterllama/modeling_posterllama.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
from_pretrained
classmethod
¶
from_pretrained(
pretrained_model_name_or_path: str | PathLike[str],
*,
local_files_only: bool = False,
subfolder: str | None = None,
) -> "PosterLlamaRuntime"
Load runtime metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Runtime directory. |
required |
local_files_only
|
bool
|
Accepted for loader compatibility. |
False
|
subfolder
|
str | None
|
Optional subfolder. |
None
|
Returns:
| Type | Description |
|---|---|
'PosterLlamaRuntime'
|
PosterLlamaRuntime instance. |
Source code in models/posterllama/src/posterllama/modeling_posterllama.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
pipeline_posterllama ¶
Pipeline orchestration for PosterLlama inference recipes.
PosterLlamaPipeline ¶
Bases: LayoutGenerationPipeline
Compose a PosterLlama processor and converted runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PosterLlamaConfig
|
Explicit pipeline configuration. |
required |
processor
|
PosterLlamaProcessor
|
Explicit processor. |
required |
runtime
|
PosterLlamaRuntime | None
|
Optional converted runtime. Parser-only saved artifacts may omit it. |
None
|
Examples:
>>> cfg = PosterLlamaConfig(canvas_size=(100, 100))
>>> text = '<svg width="100" height="100"><rect data-category="text" x="0" y="0" width="10" height="10"/></svg>'
>>> pipe = PosterLlamaPipeline(
... config=cfg,
... processor=PosterLlamaProcessor.from_config(cfg),
... runtime=PosterLlamaRuntime(text),
... )
>>> pipe(images=None).bbox.shape
torch.Size([1, 1, 4])
Source code in models/posterllama/src/posterllama/pipeline_posterllama.py
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 | |
__init__ ¶
__init__(
*,
config: PosterLlamaConfig,
processor: PosterLlamaProcessor,
runtime: PosterLlamaRuntime | None = None,
) -> None
Initialize pipeline components.
Source code in models/posterllama/src/posterllama/pipeline_posterllama.py
92 93 94 95 96 97 98 99 100 101 102 103 | |
__call__ ¶
__call__(
*,
images: ImageInput | Sequence[ImageInput] | None = None,
prompt: str | Sequence[str] | None = None,
content: Mapping[str, str | int | float | bool | None]
| Sequence[
Mapping[str, str | int | float | bool | None]
]
| None = None,
texts: str
| Sequence[str]
| Sequence[Sequence[str]]
| None = None,
batch_size: int = 1,
seed: int | None = None,
generator: Generator | None = None,
condition_type: ConditionType
| str = ConditionType.content_image,
labels: Int[Tensor, "..."]
| Sequence[Sequence[int | str]]
| Sequence[int | str]
| None = None,
bbox: Float[Tensor, "..."]
| Sequence[Sequence[Sequence[float | int]]]
| Sequence[Sequence[float | int]]
| Sequence[float | int]
| None = None,
mask: Bool[Tensor, "..."]
| Sequence[Sequence[bool]]
| Sequence[bool]
| None = None,
num_elements: int
| Sequence[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: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
max_new_tokens: int | None = None,
do_sample: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
top_k: int | None = None,
num_beams: int | None = None,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| dict[int, str]
| Mapping[
str, str | bytes | int | float | bool | None
]
| list[str]
| list[tuple[float, float, float, float]]
| tuple[int, int]
| str
| bytes
| int
| float
| bool
| None,
]
)
Generate a poster layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | Sequence[ImageInput] | None
|
Poster image inputs. |
None
|
prompt
|
str | Sequence[str] | None
|
Optional prompt prefix override. |
None
|
content
|
Mapping[str, str | int | float | bool | None] | Sequence[Mapping[str, str | int | float | bool | None]] | None
|
Optional content metadata. |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional poster text strings. |
None
|
batch_size
|
int
|
Batch size when images are omitted. |
1
|
seed
|
int | None
|
Convenience seed used only when |
None
|
generator
|
Generator | None
|
Explicit PyTorch generator; takes precedence over |
None
|
condition_type
|
ConditionType | str
|
Canonical condition or PosterLlama release alias. |
content_image
|
labels
|
Int[Tensor, '...'] | Sequence[Sequence[int | str]] | Sequence[int | str] | None
|
Optional label constraints. |
None
|
bbox
|
Float[Tensor, '...'] | Sequence[Sequence[Sequence[float | int]]] | Sequence[Sequence[float | int]] | Sequence[float | int] | None
|
Optional box constraints. |
None
|
mask
|
Bool[Tensor, '...'] | Sequence[Sequence[bool]] | Sequence[bool] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | Sequence[int] | Int[Tensor, 'batch'] | None
|
Optional requested element count. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Canvas size as |
None
|
num_inference_steps
|
int | None
|
Reserved shared argument. |
None
|
output_type
|
Literal['dataclass', 'dict']
|
|
'dataclass'
|
return_intermediates
|
bool
|
Whether to include prompt and parse diagnostics. |
False
|
max_new_tokens
|
int | None
|
Generation token budget. |
None
|
do_sample
|
bool | None
|
Sampling flag. |
None
|
temperature
|
float | None
|
Sampling temperature. |
None
|
top_p
|
float | None
|
Nucleus sampling value. |
None
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
num_beams
|
int | None
|
Beam count. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | dict[int, str] | Mapping[str, str | bytes | int | float | bool | None] | list[str] | list[tuple[float, float, float, float]] | tuple[int, int] | str | bytes | int | float | bool | None]
|
LayoutGenerationOutput or dictionary. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If converted runtime assets are absent. |
Source code in models/posterllama/src/posterllama/pipeline_posterllama.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 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 | |
postprocessing ¶
HTML/SVG postprocessing for PosterLlama generated layouts.
ParsedPosterRectangle
dataclass
¶
One parsed PosterLlama rectangle in source pixel ltwh format.
Source code in models/posterllama/src/posterllama/postprocessing.py
30 31 32 33 34 35 36 | |
ParsedPosterMarkup
dataclass
¶
Parsed PosterLlama markup and diagnostics.
Source code in models/posterllama/src/posterllama/postprocessing.py
39 40 41 42 43 44 45 | |
extract_svg_canvas ¶
extract_svg_canvas(markup: str) -> tuple[int, int] | None
Extract (width, height) from the first <svg> element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markup
|
str
|
Generated HTML/SVG text. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
Canvas size when both dimensions are present; otherwise |
Examples:
>>> extract_svg_canvas('<svg width="360" height="504"></svg>')
(360, 504)
Source code in models/posterllama/src/posterllama/postprocessing.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
parse_rectangles ¶
parse_rectangles(
markup: str,
label2id: Mapping[str, int],
*,
strict: bool = False,
) -> ParsedPosterMarkup
Parse generated <rect> tags into rectangle records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markup
|
str
|
Generated HTML/SVG text. |
required |
label2id
|
Mapping[str, int]
|
Normalized label-name to dataset id mapping. |
required |
strict
|
bool
|
Whether malformed rectangles and unknown labels raise errors. |
False
|
Returns:
| Type | Description |
|---|---|
ParsedPosterMarkup
|
Parsed rectangles, canvas size, and warnings. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> parsed = parse_rectangles(
... '<svg width="100" height="100"><rect data-category="text" x="1" y="2" width="3" height="4"/></svg>',
... {"text": 1},
... )
>>> parsed.rectangles[0].bbox_ltwh
(1.0, 2.0, 3.0, 4.0)
Source code in models/posterllama/src/posterllama/postprocessing.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 | |
rect_ltwh_to_output ¶
rect_ltwh_to_output(
parsed: ParsedPosterMarkup,
*,
canvas_size: tuple[int, int],
id2label: Mapping[int, str],
return_intermediates: bool = False,
) -> LayoutGenerationOutput
Convert parsed pixel ltwh rectangles to public layout output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsed
|
ParsedPosterMarkup
|
Parsed rectangle records. |
required |
canvas_size
|
tuple[int, int]
|
Canvas size as |
required |
id2label
|
Mapping[int, str]
|
Dataset-local id-to-label mapping. |
required |
return_intermediates
|
bool
|
Whether to include parser diagnostics. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput
|
LayoutGenerationOutput with normalized center |
Examples:
>>> parsed = ParsedPosterMarkup((ParsedPosterRectangle(1, "text", (0, 0, 10, 20)),), (100, 100), ())
>>> rect_ltwh_to_output(parsed, canvas_size=(100, 100), id2label={1: "text"}).bbox.shape
torch.Size([1, 1, 4])
Source code in models/posterllama/src/posterllama/postprocessing.py
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 | |
processing_posterllama ¶
Processor for PosterLlama prompt construction and output parsing.
PosterLlamaProcessor ¶
Bases: ProcessorMixin
Build PosterLlama prompts and decode generated HTML/SVG layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_processor
|
PosterLlamaImageProcessor
|
Image processor metadata wrapper. |
required |
config
|
PosterLlamaConfig
|
Explicit PosterLlama configuration. |
required |
Examples:
>>> processor = PosterLlamaProcessor.from_config(PosterLlamaConfig())
>>> "Generate poster layout" in processor.build_prompt(condition_type="unconditional")
True
Source code in models/posterllama/src/posterllama/processing_posterllama.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |
__init__ ¶
__init__(
image_processor: PosterLlamaImageProcessor,
config: PosterLlamaConfig,
) -> None
Initialize processor components.
Source code in models/posterllama/src/posterllama/processing_posterllama.py
108 109 110 111 112 113 114 115 116 | |
from_config
classmethod
¶
from_config(
config: PosterLlamaConfig,
) -> "PosterLlamaProcessor"
Create a processor from an explicit config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PosterLlamaConfig
|
Processor configuration. |
required |
Returns:
| Type | Description |
|---|---|
'PosterLlamaProcessor'
|
PosterLlamaProcessor instance. |
Examples:
>>> PosterLlamaProcessor.from_config(PosterLlamaConfig()).config.model_type
'posterllama'
Source code in models/posterllama/src/posterllama/processing_posterllama.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
save_pretrained ¶
save_pretrained(
save_directory: str | PathLike[str],
push_to_hub: bool = False,
**kwargs: str | int | float | bool | None,
) -> None
Save processor metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | PathLike[str]
|
Directory to write. |
required |
push_to_hub
|
bool
|
Accepted for ProcessorMixin compatibility; ignored. |
False
|
kwargs
|
str | int | float | bool | None
|
Accepted for ProcessorMixin compatibility; ignored. |
{}
|
Source code in models/posterllama/src/posterllama/processing_posterllama.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 | |
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",
*,
subfolder: str | None = None,
**kwargs: PosterLlamaImageProcessorKwarg,
) -> "PosterLlamaProcessor"
Load processor metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Checkpoint root or processor folder. |
required |
cache_dir
|
str | PathLike[str] | None
|
Accepted for ProcessorMixin compatibility. |
None
|
force_download
|
bool
|
Accepted for ProcessorMixin compatibility. |
False
|
local_files_only
|
bool
|
Whether to avoid network access. |
False
|
token
|
str | bool | None
|
Accepted for ProcessorMixin compatibility. |
None
|
revision
|
str
|
Accepted for ProcessorMixin compatibility. |
'main'
|
subfolder
|
str | None
|
Optional processor subfolder. |
None
|
kwargs
|
PosterLlamaImageProcessorKwarg
|
Accepted for ProcessorMixin compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
'PosterLlamaProcessor'
|
Loaded PosterLlamaProcessor. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |
normalize_condition_type ¶
normalize_condition_type(
condition_type: ConditionType | str,
) -> ConditionType
Normalize PosterLlama condition aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str
|
Canonical condition or PosterLlama release alias. |
required |
Returns:
| Type | Description |
|---|---|
ConditionType
|
Supported canonical condition. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the condition is known but unsupported. |
ValueError
|
If the condition is unknown. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |
__call__ ¶
__call__(
*,
images: ImageInput | Sequence[ImageInput] | None = None,
prompt: str | Sequence[str] | None = None,
content: Mapping[str, str | int | float | bool | None]
| Sequence[
Mapping[str, str | int | float | bool | None]
]
| None = None,
texts: str
| Sequence[str]
| Sequence[Sequence[str]]
| None = None,
batch_size: int = 1,
condition_type: ConditionType
| str = ConditionType.content_image,
labels: Int[Tensor, "..."]
| Sequence[Sequence[int | str]]
| Sequence[int | str]
| None = None,
bbox: Float[Tensor, "..."]
| Sequence[Sequence[Sequence[float | int]]]
| Sequence[Sequence[float | int]]
| Sequence[float | int]
| None = None,
mask: Bool[Tensor, "..."]
| Sequence[Sequence[bool]]
| Sequence[bool]
| None = None,
num_elements: int
| Sequence[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Encode public inputs into recipe prompt and image tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
ImageInput | Sequence[ImageInput] | None
|
Poster image inputs. |
None
|
prompt
|
str | Sequence[str] | None
|
Optional user-provided prompt text. |
None
|
content
|
Mapping[str, str | int | float | bool | None] | Sequence[Mapping[str, str | int | float | bool | None]] | None
|
Optional content metadata. |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional poster text strings. |
None
|
batch_size
|
int
|
Batch size when no images are supplied. |
1
|
condition_type
|
ConditionType | str
|
Canonical condition or PosterLlama release alias. |
content_image
|
labels
|
Int[Tensor, '...'] | Sequence[Sequence[int | str]] | Sequence[int | str] | None
|
Optional element label constraints. |
None
|
bbox
|
Float[Tensor, '...'] | Sequence[Sequence[Sequence[float | int]]] | Sequence[Sequence[float | int]] | Sequence[float | int] | None
|
Optional element boxes. |
None
|
mask
|
Bool[Tensor, '...'] | Sequence[Sequence[bool]] | Sequence[bool] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | Sequence[int] | Int[Tensor, 'batch'] | None
|
Optional requested element count. |
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 and prompt rendering. |
None
|
return_tensors
|
Literal['pt']
|
Tensor return format. Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
BatchEncoding containing prompt strings and tensors. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |
build_prompt ¶
build_prompt(
*,
condition_type: ConditionType
| str = ConditionType.content_image,
prompt: str | Sequence[str] | None = None,
content: Mapping[str, str | int | float | bool | None]
| Sequence[
Mapping[str, str | int | float | bool | None]
]
| None = None,
texts: str
| Sequence[str]
| Sequence[Sequence[str]]
| None = None,
labels: Int[Tensor, "..."]
| Sequence[Sequence[int | str]]
| Sequence[int | str]
| None = None,
bbox: Float[Tensor, "..."]
| Sequence[Sequence[Sequence[float | int]]]
| Sequence[Sequence[float | int]]
| Sequence[float | int]
| None = None,
mask: Bool[Tensor, "..."]
| Sequence[Sequence[bool]]
| Sequence[bool]
| None = None,
num_elements: int
| Sequence[int]
| Int[Tensor, "batch"]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
) -> str | list[str]
Build a deterministic PosterLlama HTML prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_type
|
ConditionType | str
|
Canonical condition or PosterLlama release alias. |
content_image
|
prompt
|
str | Sequence[str] | None
|
Optional prompt prefix override. |
None
|
content
|
Mapping[str, str | int | float | bool | None] | Sequence[Mapping[str, str | int | float | bool | None]] | None
|
Optional content metadata included in diagnostics text. |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional poster text strings. |
None
|
labels
|
Int[Tensor, '...'] | Sequence[Sequence[int | str]] | Sequence[int | str] | None
|
Optional label constraints. |
None
|
bbox
|
Float[Tensor, '...'] | Sequence[Sequence[Sequence[float | int]]] | Sequence[Sequence[float | int]] | Sequence[float | int] | None
|
Optional box constraints. |
None
|
mask
|
Bool[Tensor, '...'] | Sequence[Sequence[bool]] | Sequence[bool] | None
|
Optional valid-element mask. |
None
|
num_elements
|
int | Sequence[int] | Int[Tensor, 'batch'] | None
|
Requested element count for unconstrained slots. |
None
|
box_format
|
BoxFormat | str
|
Input box format. |
xywh
|
normalized
|
bool
|
Whether boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Canvas size as |
None
|
Returns:
| Type | Description |
|---|---|
str | list[str]
|
Prompt string or list of prompt strings. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |
parse_output ¶
parse_output(
text: str,
*,
canvas_size: tuple[int, int] | None = None,
output_type: Literal["dataclass", "dict"] = "dataclass",
return_intermediates: bool = False,
strict: bool = False,
) -> (
LayoutGenerationOutput
| dict[
str,
Float[torch.Tensor, "..."]
| Int[torch.Tensor, "..."]
| Bool[torch.Tensor, "..."]
| dict[int, str]
| list[str]
| list[tuple[float, float, float, float]]
| tuple[int, int]
| str
| int
| float
| bool
| None,
]
)
Parse generated HTML/SVG into public layout output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Generated markup. |
required |
canvas_size
|
tuple[int, int] | None
|
Canvas size override. |
None
|
output_type
|
Literal['dataclass', 'dict']
|
Return dataclass or dictionary. |
'dataclass'
|
return_intermediates
|
bool
|
Whether to include parse diagnostics. |
False
|
strict
|
bool
|
Whether malformed rectangles raise. |
False
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | dict[str, Float[Tensor, '...'] | Int[Tensor, '...'] | Bool[Tensor, '...'] | dict[int, str] | list[str] | list[tuple[float, float, float, float]] | tuple[int, int] | str | int | float | bool | None]
|
LayoutGenerationOutput or dictionary. |
Source code in models/posterllama/src/posterllama/processing_posterllama.py
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 | |