Posterllava
PosterLLaVA processor and inference recipe.
PosterLlavaConfig ¶
Bases: PretrainedConfig
Configuration saved with a PosterLLaVA recipe checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_id
|
str
|
Upstream LLaVA-style checkpoint id used by local smoke scripts and documentation. |
DEFAULT_CHECKPOINT_ID
|
dataset_name
|
DatasetName | str
|
Canonical poster/content dataset metadata key. |
ad_banner
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Persisted label metadata. Open-vocabulary generation uses a batch-local map at runtime, but this config records known dataset labels for model cards and smoke checks. |
None
|
prompt_template
|
str
|
Prompt body template passed through the LLaVA conversation wrapper. |
DEFAULT_PROMPT_TEMPLATE
|
default_conv_mode
|
ConversationMode | str
|
Default LLaVA conversation template. |
llava_v0
|
image_aspect_ratio
|
str
|
Image preprocessing mode; |
'pad'
|
max_new_tokens
|
int
|
Default token budget for generation. |
1024
|
default_temperature
|
float
|
Default sampled-generation temperature. |
0.2
|
processor_subfolder
|
str
|
Subfolder used by pipeline component loading. |
'processor'
|
model_subfolder
|
str
|
Optional model component subfolder. |
'model'
|
tokenizer_subfolder
|
str
|
Optional tokenizer component subfolder. |
'tokenizer'
|
image_processor_subfolder
|
str
|
Optional image processor component subfolder. |
'image_processor'
|
kwargs
|
PosterLlavaConfigValue
|
Extra Hugging Face config fields. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If numeric fields or enum-like fields are invalid. |
Examples:
>>> cfg = PosterLlavaConfig(dataset_name="ad_banner")
>>> cfg.checkpoint_id
'posterllava/posterllava_v0'
Source code in models/posterllava/src/posterllava/configuration_posterllava.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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
__init__ ¶
__init__(
*,
checkpoint_id: str = DEFAULT_CHECKPOINT_ID,
dataset_name: DatasetName | str = DatasetName.ad_banner,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
prompt_template: str = DEFAULT_PROMPT_TEMPLATE,
default_conv_mode: ConversationMode
| str = ConversationMode.llava_v0,
image_aspect_ratio: str = "pad",
max_new_tokens: int = 1024,
default_temperature: float = 0.2,
processor_subfolder: str = "processor",
model_subfolder: str = "model",
tokenizer_subfolder: str = "tokenizer",
image_processor_subfolder: str = "image_processor",
**kwargs: PosterLlavaConfigValue,
) -> None
Initialize PosterLLaVA recipe configuration.
Source code in models/posterllava/src/posterllava/configuration_posterllava.py
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 | |
PosterLlavaImageProcessor ¶
Bases: CLIPImageProcessor
CLIP image processor with PosterLLaVA square-padding behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
Keyword arguments forwarded to |
required |
Examples:
>>> from PIL import Image
>>> processor = PosterLlavaImageProcessor()
>>> image = Image.new("RGB", (8, 4))
>>> processor.expand_to_square(image).size
(8, 8)
Source code in models/posterllava/src/posterllava/image_processing_posterllava.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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
expand_to_square ¶
expand_to_square(image: Image) -> Image.Image
Pad an image to a square using the configured CLIP mean color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
RGB image to pad. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Square RGB image. |
Source code in models/posterllava/src/posterllava/image_processing_posterllava.py
38 39 40 41 42 43 44 45 46 47 | |
preprocess ¶
preprocess(
images: Image | Sequence[Image],
*,
image_aspect_ratio: Literal["pad"] = "pad",
return_tensors: str | None = "pt",
**kwargs: PosterLlavaImageProcessorKwarg,
) -> BatchFeature
Preprocess images with PosterLLaVA's square-padding policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
Image | Sequence[Image]
|
One image or a sequence of images. |
required |
image_aspect_ratio
|
Literal['pad']
|
Only |
'pad'
|
return_tensors
|
str | None
|
Tensor container requested from Transformers. |
'pt'
|
kwargs
|
PosterLlavaImageProcessorKwarg
|
Additional |
{}
|
Returns:
| Type | Description |
|---|---|
BatchFeature
|
Batch feature with processed image tensors. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in models/posterllava/src/posterllava/image_processing_posterllava.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
PosterLlavaPipeline ¶
Bases: LayoutGenerationPipeline
Generate poster layouts with a LLaVA-style causal LM checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PosterLlavaConfig
|
PosterLLaVA recipe configuration. |
required |
processor
|
PosterLlavaProcessor
|
Prompt and JSON layout processor. |
required |
model
|
PreTrainedModel | None
|
Optional upstream causal LM component. |
None
|
tokenizer
|
PreTrainedTokenizerBase | None
|
Optional LLaVA tokenizer component. |
None
|
image_processor
|
PosterLlavaImageProcessorComponent | None
|
Optional CLIP image processor component. |
None
|
Examples:
>>> cfg = PosterLlavaConfig(dataset_name="ad_banner")
>>> processor = PosterLlavaProcessor.from_config()
>>> pipe = PosterLlavaPipeline(cfg, processor)
>>> pipe.config.model_type
'posterllava'
Source code in models/posterllava/src/posterllava/pipeline_posterllava.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 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 | |
__init__ ¶
__init__(
config: PosterLlavaConfig,
processor: PosterLlavaProcessor,
*,
model: PreTrainedModel | None = None,
tokenizer: PreTrainedTokenizerBase | None = None,
image_processor: PosterLlavaImageProcessorComponent
| None = None,
) -> None
Initialize the PosterLLaVA recipe pipeline.
Source code in models/posterllava/src/posterllava/pipeline_posterllava.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
__call__ ¶
__call__(
*,
images: Image | Sequence[Image] | None = None,
prompt: str | Sequence[str] | None = None,
content: Mapping[str, PosterLlavaContentValue]
| Sequence[Mapping[str, PosterLlavaContentValue]]
| 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, "batch elements"]
| Sequence[str | int]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Sequence[Sequence[float]]
| None = None,
mask: Bool[Tensor, "batch elements"]
| 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: OutputType
| Literal["dataclass", "dict"] = OutputType.dataclass,
return_intermediates: bool = False,
max_new_tokens: int | None = None,
do_sample: bool = True,
temperature: float | None = None,
top_p: float | None = 1.0,
top_k: int | None = None,
num_beams: int | None = 1,
conv_mode: ConversationMode | str | None = None,
domain_name: str = "social media promotion poster with qbposter style",
) -> LayoutGenerationOutput | PosterLlavaOutputDict
Generate a poster layout from an image-conditioned prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
Image | Sequence[Image] | None
|
Poster/background image or image batch. |
None
|
prompt
|
str | Sequence[str] | None
|
Optional prompt body override. |
None
|
content
|
Mapping[str, PosterLlavaContentValue] | Sequence[Mapping[str, PosterLlavaContentValue]] | None
|
Optional payload mapping containing |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional aligned text payload. |
None
|
batch_size
|
int
|
Expected batch size when scalar inputs are provided. |
1
|
seed
|
int | None
|
Seed used only when |
None
|
generator
|
Generator | None
|
Explicit generator passed to model generation. |
None
|
condition_type
|
ConditionType | str
|
Canonical condition type. Only |
content_image
|
labels
|
Int[Tensor, 'batch elements'] | Sequence[str | int] | None
|
Optional initial labels. |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | Sequence[Sequence[float]] | None
|
Optional initial boxes aligned with labels. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Sequence[bool] | None
|
Optional initial valid-element mask. |
None
|
num_elements
|
int | Sequence[int] | Int[Tensor, 'batch'] | None
|
Requested element count. |
None
|
box_format
|
BoxFormat | str
|
Public input box format. |
xywh
|
normalized
|
bool
|
Whether input boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size for non-normalized input boxes. |
None
|
num_inference_steps
|
int | None
|
Accepted for shared-interface compatibility. |
None
|
output_type
|
OutputType | Literal['dataclass', 'dict']
|
Output container mode. |
dataclass
|
return_intermediates
|
bool
|
Whether raw prompts/text are returned. |
False
|
max_new_tokens
|
int | None
|
Token budget for generation. |
None
|
do_sample
|
bool
|
Whether to sample from the LLM. |
True
|
temperature
|
float | None
|
Sampling temperature. |
None
|
top_p
|
float | None
|
Nucleus sampling parameter. |
1.0
|
top_k
|
int | None
|
Top-k sampling parameter. |
None
|
num_beams
|
int | None
|
Beam count. |
1
|
conv_mode
|
ConversationMode | str | None
|
Optional LLaVA conversation template override. |
None
|
domain_name
|
str
|
Domain phrase inserted into the default prompt. |
'social media promotion poster with qbposter style'
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | PosterLlavaOutputDict
|
Layout output dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
ValueError
|
If required image/model/tokenizer components are absent. |
Source code in models/posterllava/src/posterllava/pipeline_posterllava.py
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 | |
PosterLlavaProcessor ¶
Bases: ProcessorMixin
Build PosterLLaVA prompts and decode generated JSON layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
PreTrainedTokenizerBase | None
|
Optional LLaVA tokenizer used to insert the image sentinel. |
None
|
image_processor
|
PosterLlavaImageProcessorComponent | None
|
Optional image processor component. |
None
|
dataset_name
|
DatasetName | str
|
Poster/content dataset used for known label metadata. |
ad_banner
|
canvas_size
|
tuple[int, int]
|
Canvas size used when public input boxes are pixel based. |
DEFAULT_CANVAS_SIZE
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Persisted known label map. |
None
|
prompt_template
|
str
|
JSON instruction body template. |
DEFAULT_PROMPT_TEMPLATE
|
default_domain_name
|
str
|
Domain phrase inserted into prompts. |
DEFAULT_DOMAIN_NAME
|
Examples:
>>> processor = PosterLlavaProcessor.from_config()
>>> processor.parse_output("[{'label': 'text', 'box': [0, 0, 1, 1]}]")[0]["label"]
'text'
Source code in models/posterllava/src/posterllava/processing_posterllava.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 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 | |
__init__ ¶
__init__(
tokenizer: PreTrainedTokenizerBase | None = None,
image_processor: PosterLlavaImageProcessorComponent
| None = None,
dataset_name: DatasetName | str = DatasetName.ad_banner,
canvas_size: tuple[int, int] = DEFAULT_CANVAS_SIZE,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
prompt_template: str = DEFAULT_PROMPT_TEMPLATE,
default_domain_name: str = DEFAULT_DOMAIN_NAME,
) -> None
Initialize tokenizer handles and layout metadata.
Source code in models/posterllava/src/posterllava/processing_posterllava.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
from_config
classmethod
¶
from_config(
*,
dataset_name: DatasetName | str = DatasetName.ad_banner,
canvas_size: tuple[int, int] = DEFAULT_CANVAS_SIZE,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
prompt_template: str = DEFAULT_PROMPT_TEMPLATE,
default_domain_name: str = DEFAULT_DOMAIN_NAME,
) -> PosterLlavaProcessor
Construct a metadata-only processor for tests and local smoke checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Poster/content dataset key. |
ad_banner
|
canvas_size
|
tuple[int, int]
|
Canvas size used for pixel input normalization. |
DEFAULT_CANVAS_SIZE
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Optional known label map. |
None
|
prompt_template
|
str
|
Prompt body template. |
DEFAULT_PROMPT_TEMPLATE
|
default_domain_name
|
str
|
Default domain phrase. |
DEFAULT_DOMAIN_NAME
|
Returns:
| Type | Description |
|---|---|
PosterLlavaProcessor
|
Metadata-only processor. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
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: str | int | bool | list[int] | dict[str, str],
) -> PosterLlavaProcessor
Load processor metadata from a checkpoint directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Root checkpoint path. |
required |
cache_dir
|
str | PathLike[str] | None
|
Accepted for Transformers processor compatibility. |
None
|
force_download
|
bool
|
Accepted for Transformers processor compatibility. |
False
|
local_files_only
|
bool
|
Accepted for compatibility with pipeline loaders. |
False
|
token
|
str | bool | None
|
Accepted for Transformers processor compatibility. |
None
|
revision
|
str
|
Accepted for Transformers processor compatibility. |
'main'
|
subfolder
|
str | None
|
Optional processor subfolder. |
None
|
kwargs
|
str | int | bool | list[int] | dict[str, str]
|
Metadata overrides. |
{}
|
Returns:
| Type | Description |
|---|---|
PosterLlavaProcessor
|
Loaded processor. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | Path,
push_to_hub: bool = False,
**kwargs: str | int | bool | None,
) -> None
Save processor metadata and optional component processors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Directory to write. |
required |
push_to_hub
|
bool
|
Accepted for Transformers processor compatibility. |
False
|
kwargs
|
str | int | bool | None
|
Additional save options accepted for compatibility. |
{}
|
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
build_initial_json ¶
build_initial_json(
*,
labels: Sequence[str | int]
| Int[Tensor, "elements"]
| None = None,
bbox: Float[Tensor, "elements 4"]
| Sequence[Sequence[float]]
| None = None,
mask: Bool[Tensor, "elements"]
| Sequence[bool]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
) -> list[PosterLlavaJsonElement]
Build optional initial layout JSON from public layout inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Sequence[str | int] | Int[Tensor, 'elements'] | None
|
Known labels as strings or integer ids. |
None
|
bbox
|
Float[Tensor, 'elements 4'] | Sequence[Sequence[float]] | None
|
Optional boxes aligned with labels. |
None
|
mask
|
Bool[Tensor, 'elements'] | Sequence[bool] | None
|
Optional valid-element mask. |
None
|
box_format
|
BoxFormat | str
|
Public box format for |
xywh
|
normalized
|
bool
|
Whether |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size when |
None
|
Returns:
| Type | Description |
|---|---|
list[PosterLlavaJsonElement]
|
Initial JSON elements used in the prompt. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels and boxes are inconsistently shaped. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
build_prompt ¶
build_prompt(
*,
num_elements: int,
canvas_size: tuple[int, int] | None = None,
elements: Sequence[PosterLlavaJsonElement]
| Sequence[Mapping[str, PosterLlavaJsonValue]] = (),
domain_name: str | None = None,
conv_mode: ConversationMode
| str = ConversationMode.llava_v0,
prompt: str | None = None,
texts: str
| Sequence[str]
| Sequence[Sequence[str]]
| None = None,
) -> str
Build the LLaVA conversation prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_elements
|
int
|
Number of requested layout elements. |
required |
canvas_size
|
tuple[int, int] | None
|
Optional canvas metadata. Stored in prompt text only when a custom prompt uses it. |
None
|
elements
|
Sequence[PosterLlavaJsonElement] | Sequence[Mapping[str, PosterLlavaJsonValue]]
|
Optional initial layout JSON. |
()
|
domain_name
|
str | None
|
Domain phrase for the default template. |
None
|
conv_mode
|
ConversationMode | str
|
LLaVA conversation template. |
llava_v0
|
prompt
|
str | None
|
Optional user-supplied prompt body override. |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional text payload inserted into the default body. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Full conversation prompt with the |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
__call__ ¶
__call__(
prompt: str | Sequence[str],
*,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Tokenize prompts with LLaVA image-token insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str | Sequence[str]
|
Prompt string or prompt sequence. |
required |
return_tensors
|
Literal['pt']
|
Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If tokenizer is absent. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
parse_output ¶
parse_output(text: str) -> list[PosterLlavaJsonElement]
Parse the first generated JSON-like array span.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Decoded LLaVA generation text. |
required |
Returns:
| Type | Description |
|---|---|
list[PosterLlavaJsonElement]
|
Parsed element dictionaries. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no JSON array span can be parsed. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
decode_layout ¶
decode_layout(
text: str | Sequence[str],
*,
output_type: OutputType
| Literal["dataclass", "dict"] = OutputType.dataclass,
return_intermediates: bool = False,
sequences: Int[Tensor, "batch generated_tokens"]
| None = None,
prompts: Sequence[str] | None = None,
) -> LayoutGenerationOutput | PosterLlavaOutputDict
Decode generated text into the shared layout output schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | Sequence[str]
|
Generated text or batch of generated texts. |
required |
output_type
|
OutputType | Literal['dataclass', 'dict']
|
Output container mode. |
dataclass
|
return_intermediates
|
bool
|
Whether to include raw text and parser data. |
False
|
sequences
|
Int[Tensor, 'batch generated_tokens'] | None
|
Optional generated token ids. |
None
|
prompts
|
Sequence[str] | None
|
Optional prompt texts. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | PosterLlavaOutputDict
|
Layout output dataclass or dictionary. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
configuration_posterllava ¶
Configuration for PosterLLaVA recipe checkpoints.
OutputType ¶
Bases: StrEnum
Closed output container modes supported by PosterLLaVA.
Source code in models/posterllava/src/posterllava/configuration_posterllava.py
21 22 23 24 25 | |
ConversationMode ¶
Bases: StrEnum
Conversation templates used by LLaVA-family checkpoints.
Source code in models/posterllava/src/posterllava/configuration_posterllava.py
28 29 30 31 32 | |
PosterLlavaConfig ¶
Bases: PretrainedConfig
Configuration saved with a PosterLLaVA recipe checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_id
|
str
|
Upstream LLaVA-style checkpoint id used by local smoke scripts and documentation. |
DEFAULT_CHECKPOINT_ID
|
dataset_name
|
DatasetName | str
|
Canonical poster/content dataset metadata key. |
ad_banner
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Persisted label metadata. Open-vocabulary generation uses a batch-local map at runtime, but this config records known dataset labels for model cards and smoke checks. |
None
|
prompt_template
|
str
|
Prompt body template passed through the LLaVA conversation wrapper. |
DEFAULT_PROMPT_TEMPLATE
|
default_conv_mode
|
ConversationMode | str
|
Default LLaVA conversation template. |
llava_v0
|
image_aspect_ratio
|
str
|
Image preprocessing mode; |
'pad'
|
max_new_tokens
|
int
|
Default token budget for generation. |
1024
|
default_temperature
|
float
|
Default sampled-generation temperature. |
0.2
|
processor_subfolder
|
str
|
Subfolder used by pipeline component loading. |
'processor'
|
model_subfolder
|
str
|
Optional model component subfolder. |
'model'
|
tokenizer_subfolder
|
str
|
Optional tokenizer component subfolder. |
'tokenizer'
|
image_processor_subfolder
|
str
|
Optional image processor component subfolder. |
'image_processor'
|
kwargs
|
PosterLlavaConfigValue
|
Extra Hugging Face config fields. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If numeric fields or enum-like fields are invalid. |
Examples:
>>> cfg = PosterLlavaConfig(dataset_name="ad_banner")
>>> cfg.checkpoint_id
'posterllava/posterllava_v0'
Source code in models/posterllava/src/posterllava/configuration_posterllava.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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
__init__ ¶
__init__(
*,
checkpoint_id: str = DEFAULT_CHECKPOINT_ID,
dataset_name: DatasetName | str = DatasetName.ad_banner,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
prompt_template: str = DEFAULT_PROMPT_TEMPLATE,
default_conv_mode: ConversationMode
| str = ConversationMode.llava_v0,
image_aspect_ratio: str = "pad",
max_new_tokens: int = 1024,
default_temperature: float = 0.2,
processor_subfolder: str = "processor",
model_subfolder: str = "model",
tokenizer_subfolder: str = "tokenizer",
image_processor_subfolder: str = "image_processor",
**kwargs: PosterLlavaConfigValue,
) -> None
Initialize PosterLLaVA recipe configuration.
Source code in models/posterllava/src/posterllava/configuration_posterllava.py
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 | |
normalize_output_type ¶
normalize_output_type(
output_type: OutputType | str,
) -> OutputType
Normalize a public output-type value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
OutputType | str
|
Output type enum or string value. |
required |
Returns:
| Type | Description |
|---|---|
OutputType
|
Normalized output type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the value is unsupported. |
Examples:
>>> str(normalize_output_type("dict"))
'dict'
Source code in models/posterllava/src/posterllava/configuration_posterllava.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
normalize_conversation_mode ¶
normalize_conversation_mode(
conversation_mode: ConversationMode | str,
) -> ConversationMode
Normalize a LLaVA conversation mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_mode
|
ConversationMode | str
|
Conversation mode enum or string value. |
required |
Returns:
| Type | Description |
|---|---|
ConversationMode
|
Normalized conversation mode. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the mode is unsupported. |
Source code in models/posterllava/src/posterllava/configuration_posterllava.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
generation_posterllava ¶
Generation helpers for PosterLLaVA pipeline orchestration.
StopStringCriteria ¶
Bases: StoppingCriteria
Stop generation once decoded text contains any configured stop string.
Source code in models/posterllava/src/posterllava/generation_posterllava.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
__init__ ¶
__init__(
tokenizer: PreTrainedTokenizerBase,
*,
input_length: int,
stop_strings: Sequence[str],
) -> None
Store tokenizer and decoded suffix matching configuration.
Source code in models/posterllava/src/posterllava/generation_posterllava.py
86 87 88 89 90 91 92 93 94 95 96 | |
__call__ ¶
__call__(
input_ids: Int[Tensor, "batch tokens"],
scores: Float[Tensor, "batch vocab"],
**kwargs: str | int | float | bool | None,
) -> bool
Return whether any batch item has reached a stop string.
Source code in models/posterllava/src/posterllava/generation_posterllava.py
98 99 100 101 102 103 104 105 106 107 108 | |
infer_conversation_mode ¶
infer_conversation_mode(
model_name: str, override: str | None = None
) -> Literal["llava_v0", "llava_v1"]
Infer the LLaVA conversation mode used by a checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Checkpoint id or local model name. |
required |
override
|
str | None
|
Explicit mode. When provided, it is validated and returned. |
None
|
Returns:
| Type | Description |
|---|---|
Literal['llava_v0', 'llava_v1']
|
Supported conversation mode. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the override is unsupported. |
Examples:
>>> infer_conversation_mode("posterllava/posterllava_v0")
'llava_v0'
Source code in models/posterllava/src/posterllava/generation_posterllava.py
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 | |
tokenizer_image_token ¶
tokenizer_image_token(
prompt: str,
tokenizer: PreTrainedTokenizerBase,
*,
image_token_index: int = IMAGE_TOKEN_INDEX,
return_tensors: Literal["pt"] = "pt",
) -> Int[torch.Tensor, "tokens"]
Tokenize a prompt while replacing <image> with LLaVA's image id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Prompt text containing zero or more |
required |
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer used for surrounding text chunks. |
required |
image_token_index
|
int
|
Sentinel id inserted between text chunks. |
IMAGE_TOKEN_INDEX
|
return_tensors
|
Literal['pt']
|
Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
Int[Tensor, 'tokens']
|
One-dimensional token id tensor. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a non-PyTorch return type is requested. |
Source code in models/posterllava/src/posterllava/generation_posterllava.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
build_stopping_criteria ¶
build_stopping_criteria(
tokenizer: PreTrainedTokenizerBase,
*,
input_ids: Int[Tensor, "batch tokens"],
stop_strings: Sequence[str] = DEFAULT_STOP_STRINGS,
) -> StoppingCriteriaList
Build LLaVA-style stop-string criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer used for decoding generated suffixes. |
required |
input_ids
|
Int[Tensor, 'batch tokens']
|
Prompt token ids whose length should be ignored. |
required |
stop_strings
|
Sequence[str]
|
Stop strings to detect in generated text. |
DEFAULT_STOP_STRINGS
|
Returns:
| Type | Description |
|---|---|
StoppingCriteriaList
|
Transformers stopping criteria list. |
Source code in models/posterllava/src/posterllava/generation_posterllava.py
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_posterllava ¶
Image preprocessing helpers for PosterLLaVA.
PosterLlavaImageProcessor ¶
Bases: CLIPImageProcessor
CLIP image processor with PosterLLaVA square-padding behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
Keyword arguments forwarded to |
required |
Examples:
>>> from PIL import Image
>>> processor = PosterLlavaImageProcessor()
>>> image = Image.new("RGB", (8, 4))
>>> processor.expand_to_square(image).size
(8, 8)
Source code in models/posterllava/src/posterllava/image_processing_posterllava.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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
expand_to_square ¶
expand_to_square(image: Image) -> Image.Image
Pad an image to a square using the configured CLIP mean color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
RGB image to pad. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
Square RGB image. |
Source code in models/posterllava/src/posterllava/image_processing_posterllava.py
38 39 40 41 42 43 44 45 46 47 | |
preprocess ¶
preprocess(
images: Image | Sequence[Image],
*,
image_aspect_ratio: Literal["pad"] = "pad",
return_tensors: str | None = "pt",
**kwargs: PosterLlavaImageProcessorKwarg,
) -> BatchFeature
Preprocess images with PosterLLaVA's square-padding policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
Image | Sequence[Image]
|
One image or a sequence of images. |
required |
image_aspect_ratio
|
Literal['pad']
|
Only |
'pad'
|
return_tensors
|
str | None
|
Tensor container requested from Transformers. |
'pt'
|
kwargs
|
PosterLlavaImageProcessorKwarg
|
Additional |
{}
|
Returns:
| Type | Description |
|---|---|
BatchFeature
|
Batch feature with processed image tensors. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in models/posterllava/src/posterllava/image_processing_posterllava.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
model_card ¶
Hub model-card generation helpers for PosterLLaVA.
build_posterllava_model_card ¶
build_posterllava_model_card(
*,
model_id: str = "creative-graphic-design/posterllava-v0",
) -> ModelCard
Build a PosterLLaVA Hub model-card draft.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
Planned Hub model id. |
'creative-graphic-design/posterllava-v0'
|
Returns:
| Type | Description |
|---|---|
ModelCard
|
Hugging Face model card object. |
Examples:
>>> card = build_posterllava_model_card()
>>> card.data.to_dict()["library_name"]
'transformers'
Source code in models/posterllava/src/posterllava/model_card.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 | |
pipeline_posterllava ¶
Pipeline wrapper for PosterLLaVA image-conditioned layout generation.
PosterLlavaPipeline ¶
Bases: LayoutGenerationPipeline
Generate poster layouts with a LLaVA-style causal LM checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PosterLlavaConfig
|
PosterLLaVA recipe configuration. |
required |
processor
|
PosterLlavaProcessor
|
Prompt and JSON layout processor. |
required |
model
|
PreTrainedModel | None
|
Optional upstream causal LM component. |
None
|
tokenizer
|
PreTrainedTokenizerBase | None
|
Optional LLaVA tokenizer component. |
None
|
image_processor
|
PosterLlavaImageProcessorComponent | None
|
Optional CLIP image processor component. |
None
|
Examples:
>>> cfg = PosterLlavaConfig(dataset_name="ad_banner")
>>> processor = PosterLlavaProcessor.from_config()
>>> pipe = PosterLlavaPipeline(cfg, processor)
>>> pipe.config.model_type
'posterllava'
Source code in models/posterllava/src/posterllava/pipeline_posterllava.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 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 | |
__init__ ¶
__init__(
config: PosterLlavaConfig,
processor: PosterLlavaProcessor,
*,
model: PreTrainedModel | None = None,
tokenizer: PreTrainedTokenizerBase | None = None,
image_processor: PosterLlavaImageProcessorComponent
| None = None,
) -> None
Initialize the PosterLLaVA recipe pipeline.
Source code in models/posterllava/src/posterllava/pipeline_posterllava.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
__call__ ¶
__call__(
*,
images: Image | Sequence[Image] | None = None,
prompt: str | Sequence[str] | None = None,
content: Mapping[str, PosterLlavaContentValue]
| Sequence[Mapping[str, PosterLlavaContentValue]]
| 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, "batch elements"]
| Sequence[str | int]
| None = None,
bbox: Float[Tensor, "batch elements 4"]
| Sequence[Sequence[float]]
| None = None,
mask: Bool[Tensor, "batch elements"]
| 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: OutputType
| Literal["dataclass", "dict"] = OutputType.dataclass,
return_intermediates: bool = False,
max_new_tokens: int | None = None,
do_sample: bool = True,
temperature: float | None = None,
top_p: float | None = 1.0,
top_k: int | None = None,
num_beams: int | None = 1,
conv_mode: ConversationMode | str | None = None,
domain_name: str = "social media promotion poster with qbposter style",
) -> LayoutGenerationOutput | PosterLlavaOutputDict
Generate a poster layout from an image-conditioned prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
Image | Sequence[Image] | None
|
Poster/background image or image batch. |
None
|
prompt
|
str | Sequence[str] | None
|
Optional prompt body override. |
None
|
content
|
Mapping[str, PosterLlavaContentValue] | Sequence[Mapping[str, PosterLlavaContentValue]] | None
|
Optional payload mapping containing |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional aligned text payload. |
None
|
batch_size
|
int
|
Expected batch size when scalar inputs are provided. |
1
|
seed
|
int | None
|
Seed used only when |
None
|
generator
|
Generator | None
|
Explicit generator passed to model generation. |
None
|
condition_type
|
ConditionType | str
|
Canonical condition type. Only |
content_image
|
labels
|
Int[Tensor, 'batch elements'] | Sequence[str | int] | None
|
Optional initial labels. |
None
|
bbox
|
Float[Tensor, 'batch elements 4'] | Sequence[Sequence[float]] | None
|
Optional initial boxes aligned with labels. |
None
|
mask
|
Bool[Tensor, 'batch elements'] | Sequence[bool] | None
|
Optional initial valid-element mask. |
None
|
num_elements
|
int | Sequence[int] | Int[Tensor, 'batch'] | None
|
Requested element count. |
None
|
box_format
|
BoxFormat | str
|
Public input box format. |
xywh
|
normalized
|
bool
|
Whether input boxes are normalized. |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size for non-normalized input boxes. |
None
|
num_inference_steps
|
int | None
|
Accepted for shared-interface compatibility. |
None
|
output_type
|
OutputType | Literal['dataclass', 'dict']
|
Output container mode. |
dataclass
|
return_intermediates
|
bool
|
Whether raw prompts/text are returned. |
False
|
max_new_tokens
|
int | None
|
Token budget for generation. |
None
|
do_sample
|
bool
|
Whether to sample from the LLM. |
True
|
temperature
|
float | None
|
Sampling temperature. |
None
|
top_p
|
float | None
|
Nucleus sampling parameter. |
1.0
|
top_k
|
int | None
|
Top-k sampling parameter. |
None
|
num_beams
|
int | None
|
Beam count. |
1
|
conv_mode
|
ConversationMode | str | None
|
Optional LLaVA conversation template override. |
None
|
domain_name
|
str
|
Domain phrase inserted into the default prompt. |
'social media promotion poster with qbposter style'
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | PosterLlavaOutputDict
|
Layout output dataclass or dictionary. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
ValueError
|
If required image/model/tokenizer components are absent. |
Source code in models/posterllava/src/posterllava/pipeline_posterllava.py
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 | |
processing_posterllava ¶
Processor for PosterLLaVA prompts and JSON layout decoding.
PosterLlavaJsonElement ¶
Bases: TypedDict
One generated PosterLLaVA JSON element.
Source code in models/posterllava/src/posterllava/processing_posterllava.py
50 51 52 53 54 | |
ParsedPosterLlavaElement ¶
Bases: TypedDict
One parsed element with batch-local numeric label id.
Source code in models/posterllava/src/posterllava/processing_posterllava.py
57 58 59 60 61 62 | |
PromptBundle ¶
Bases: TypedDict
Prompt text and normalized element metadata.
Source code in models/posterllava/src/posterllava/processing_posterllava.py
65 66 67 68 69 70 | |
PosterLlavaIntermediates ¶
Bases: TypedDict
Optional PosterLLaVA parsing and prompt metadata.
Source code in models/posterllava/src/posterllava/processing_posterllava.py
73 74 75 76 77 78 79 80 | |
PosterLlavaOutputDict ¶
Bases: TypedDict
Dictionary form of the PosterLLaVA layout output.
Source code in models/posterllava/src/posterllava/processing_posterllava.py
83 84 85 86 87 88 89 90 91 | |
PosterLlavaImageProcessorComponent ¶
Bases: Protocol
Runtime image processor component accepted by the recipe wrapper.
Source code in models/posterllava/src/posterllava/processing_posterllava.py
94 95 | |
PosterLlavaProcessor ¶
Bases: ProcessorMixin
Build PosterLLaVA prompts and decode generated JSON layouts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
PreTrainedTokenizerBase | None
|
Optional LLaVA tokenizer used to insert the image sentinel. |
None
|
image_processor
|
PosterLlavaImageProcessorComponent | None
|
Optional image processor component. |
None
|
dataset_name
|
DatasetName | str
|
Poster/content dataset used for known label metadata. |
ad_banner
|
canvas_size
|
tuple[int, int]
|
Canvas size used when public input boxes are pixel based. |
DEFAULT_CANVAS_SIZE
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Persisted known label map. |
None
|
prompt_template
|
str
|
JSON instruction body template. |
DEFAULT_PROMPT_TEMPLATE
|
default_domain_name
|
str
|
Domain phrase inserted into prompts. |
DEFAULT_DOMAIN_NAME
|
Examples:
>>> processor = PosterLlavaProcessor.from_config()
>>> processor.parse_output("[{'label': 'text', 'box': [0, 0, 1, 1]}]")[0]["label"]
'text'
Source code in models/posterllava/src/posterllava/processing_posterllava.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 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 | |
__init__ ¶
__init__(
tokenizer: PreTrainedTokenizerBase | None = None,
image_processor: PosterLlavaImageProcessorComponent
| None = None,
dataset_name: DatasetName | str = DatasetName.ad_banner,
canvas_size: tuple[int, int] = DEFAULT_CANVAS_SIZE,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
prompt_template: str = DEFAULT_PROMPT_TEMPLATE,
default_domain_name: str = DEFAULT_DOMAIN_NAME,
) -> None
Initialize tokenizer handles and layout metadata.
Source code in models/posterllava/src/posterllava/processing_posterllava.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
from_config
classmethod
¶
from_config(
*,
dataset_name: DatasetName | str = DatasetName.ad_banner,
canvas_size: tuple[int, int] = DEFAULT_CANVAS_SIZE,
id2label: Mapping[int, str]
| Mapping[str, str]
| None = None,
prompt_template: str = DEFAULT_PROMPT_TEMPLATE,
default_domain_name: str = DEFAULT_DOMAIN_NAME,
) -> PosterLlavaProcessor
Construct a metadata-only processor for tests and local smoke checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
DatasetName | str
|
Poster/content dataset key. |
ad_banner
|
canvas_size
|
tuple[int, int]
|
Canvas size used for pixel input normalization. |
DEFAULT_CANVAS_SIZE
|
id2label
|
Mapping[int, str] | Mapping[str, str] | None
|
Optional known label map. |
None
|
prompt_template
|
str
|
Prompt body template. |
DEFAULT_PROMPT_TEMPLATE
|
default_domain_name
|
str
|
Default domain phrase. |
DEFAULT_DOMAIN_NAME
|
Returns:
| Type | Description |
|---|---|
PosterLlavaProcessor
|
Metadata-only processor. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
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: str | int | bool | list[int] | dict[str, str],
) -> PosterLlavaProcessor
Load processor metadata from a checkpoint directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretrained_model_name_or_path
|
str | PathLike[str]
|
Root checkpoint path. |
required |
cache_dir
|
str | PathLike[str] | None
|
Accepted for Transformers processor compatibility. |
None
|
force_download
|
bool
|
Accepted for Transformers processor compatibility. |
False
|
local_files_only
|
bool
|
Accepted for compatibility with pipeline loaders. |
False
|
token
|
str | bool | None
|
Accepted for Transformers processor compatibility. |
None
|
revision
|
str
|
Accepted for Transformers processor compatibility. |
'main'
|
subfolder
|
str | None
|
Optional processor subfolder. |
None
|
kwargs
|
str | int | bool | list[int] | dict[str, str]
|
Metadata overrides. |
{}
|
Returns:
| Type | Description |
|---|---|
PosterLlavaProcessor
|
Loaded processor. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
save_pretrained ¶
save_pretrained(
save_directory: str | Path,
push_to_hub: bool = False,
**kwargs: str | int | bool | None,
) -> None
Save processor metadata and optional component processors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
str | Path
|
Directory to write. |
required |
push_to_hub
|
bool
|
Accepted for Transformers processor compatibility. |
False
|
kwargs
|
str | int | bool | None
|
Additional save options accepted for compatibility. |
{}
|
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
build_initial_json ¶
build_initial_json(
*,
labels: Sequence[str | int]
| Int[Tensor, "elements"]
| None = None,
bbox: Float[Tensor, "elements 4"]
| Sequence[Sequence[float]]
| None = None,
mask: Bool[Tensor, "elements"]
| Sequence[bool]
| None = None,
box_format: BoxFormat | str = BoxFormat.xywh,
normalized: bool = True,
canvas_size: tuple[int, int] | None = None,
) -> list[PosterLlavaJsonElement]
Build optional initial layout JSON from public layout inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Sequence[str | int] | Int[Tensor, 'elements'] | None
|
Known labels as strings or integer ids. |
None
|
bbox
|
Float[Tensor, 'elements 4'] | Sequence[Sequence[float]] | None
|
Optional boxes aligned with labels. |
None
|
mask
|
Bool[Tensor, 'elements'] | Sequence[bool] | None
|
Optional valid-element mask. |
None
|
box_format
|
BoxFormat | str
|
Public box format for |
xywh
|
normalized
|
bool
|
Whether |
True
|
canvas_size
|
tuple[int, int] | None
|
Pixel canvas size when |
None
|
Returns:
| Type | Description |
|---|---|
list[PosterLlavaJsonElement]
|
Initial JSON elements used in the prompt. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If labels and boxes are inconsistently shaped. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
build_prompt ¶
build_prompt(
*,
num_elements: int,
canvas_size: tuple[int, int] | None = None,
elements: Sequence[PosterLlavaJsonElement]
| Sequence[Mapping[str, PosterLlavaJsonValue]] = (),
domain_name: str | None = None,
conv_mode: ConversationMode
| str = ConversationMode.llava_v0,
prompt: str | None = None,
texts: str
| Sequence[str]
| Sequence[Sequence[str]]
| None = None,
) -> str
Build the LLaVA conversation prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_elements
|
int
|
Number of requested layout elements. |
required |
canvas_size
|
tuple[int, int] | None
|
Optional canvas metadata. Stored in prompt text only when a custom prompt uses it. |
None
|
elements
|
Sequence[PosterLlavaJsonElement] | Sequence[Mapping[str, PosterLlavaJsonValue]]
|
Optional initial layout JSON. |
()
|
domain_name
|
str | None
|
Domain phrase for the default template. |
None
|
conv_mode
|
ConversationMode | str
|
LLaVA conversation template. |
llava_v0
|
prompt
|
str | None
|
Optional user-supplied prompt body override. |
None
|
texts
|
str | Sequence[str] | Sequence[Sequence[str]] | None
|
Optional text payload inserted into the default body. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Full conversation prompt with the |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
__call__ ¶
__call__(
prompt: str | Sequence[str],
*,
return_tensors: Literal["pt"] = "pt",
) -> BatchEncoding
Tokenize prompts with LLaVA image-token insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str | Sequence[str]
|
Prompt string or prompt sequence. |
required |
return_tensors
|
Literal['pt']
|
Only |
'pt'
|
Returns:
| Type | Description |
|---|---|
BatchEncoding
|
Batch encoding with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If tokenizer is absent. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
parse_output ¶
parse_output(text: str) -> list[PosterLlavaJsonElement]
Parse the first generated JSON-like array span.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Decoded LLaVA generation text. |
required |
Returns:
| Type | Description |
|---|---|
list[PosterLlavaJsonElement]
|
Parsed element dictionaries. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no JSON array span can be parsed. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |
decode_layout ¶
decode_layout(
text: str | Sequence[str],
*,
output_type: OutputType
| Literal["dataclass", "dict"] = OutputType.dataclass,
return_intermediates: bool = False,
sequences: Int[Tensor, "batch generated_tokens"]
| None = None,
prompts: Sequence[str] | None = None,
) -> LayoutGenerationOutput | PosterLlavaOutputDict
Decode generated text into the shared layout output schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | Sequence[str]
|
Generated text or batch of generated texts. |
required |
output_type
|
OutputType | Literal['dataclass', 'dict']
|
Output container mode. |
dataclass
|
return_intermediates
|
bool
|
Whether to include raw text and parser data. |
False
|
sequences
|
Int[Tensor, 'batch generated_tokens'] | None
|
Optional generated token ids. |
None
|
prompts
|
Sequence[str] | None
|
Optional prompt texts. |
None
|
Returns:
| Type | Description |
|---|---|
LayoutGenerationOutput | PosterLlavaOutputDict
|
Layout output dataclass or dictionary. |
Source code in models/posterllava/src/posterllava/processing_posterllava.py
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 | |