For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python function
generate_images
generate_images()
max.pipelines.lib.generate_images.generate_images(pipeline, tokenizer, prompt, *, images=None, negative_prompt=None, height=None, width=None, num_inference_steps=None, guidance_scale=None, true_cfg_scale=None, strength=None, num_images_per_prompt=1, seed=0, caller='generate_images()')
Generates images for each prompt, one prompt per pipeline run.
An argument left as None takes the model’s default, as a max serve request that omits it does.
-
Parameters:
-
- pipeline (ImagePipeline) – The image pipeline to run.
- tokenizer (ImageTokenizer) – The pipeline’s tokenizer, which builds each request’s context.
- prompt (str | Sequence[str]) – One prompt, or a list of prompts.
- images (Sequence[Sequence[bytes | Image]] | None) – One list of input images per prompt, each image encoded
bytes or a PIL image, as for
generate(). A model reads one input image, so a list holds one image, or none for a text-only prompt. Withoutheightandwidth, the output size is the input image’s size rounded down to a size the model takes. - negative_prompt (str | Sequence[str] | None) – What to steer away from, as one string for every prompt or one per prompt.
- height (int | None) – The image height in pixels.
- width (int | None) – The image width in pixels.
- num_inference_steps (int | None) – The number of denoising steps.
- guidance_scale (float | None) – How closely the image follows the prompt.
- true_cfg_scale (float | None) – The true classifier-free guidance scale. Models
that use it need it above 1 and a
negative_prompt. - strength (float | None) – How far an input image is noised, in
(0, 1]. Z-Image reads it, and FLUX.2 ignores it. - num_images_per_prompt (int) – The number of images for each prompt.
- seed (int) – The seed for prompt 0. Prompt
iuses(seed + i) % 2**32, since numpy takes 32-bit seeds. - caller (str) – What the user called, which errors name.
-
Returns:
-
One list of PIL images per prompt, in prompt order.
-
Raises:
-
- TypeError – If the pipeline’s model does not generate images, or
imagesis not a list of image lists. - ValueError – If there are no prompts, a prompt is empty or too long
for the model,
negative_promptorimageshas the wrong length, a prompt has more than one input image,num_inference_stepsornum_images_per_promptis below 1,seedis outside[0, 2**32), a value is outside the rangemax serveaccepts, the model generates video, or an input image goes to a model that takes text only. A tokenizer’s error names its prompt. Every prompt is checked before the first one runs. - RuntimeError – If the pipeline returns output that is not an image.
- OSError – If an input image’s bytes do not decode, before any prompt runs.
- TypeError – If the pipeline’s model does not generate images, or
-
Return type: