Repository navigation
poc: vllm-omni-neuron for serving FLUX.2 Klein #15249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
05d1de8
e412d83
ec2a7d0
f4b20ed
0ccbeb7
cedef4c
27bd497
8511dc4
817e86c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -115,3 +115,19 @@ Launch one process per NeuronCore. Set `--nproc_per_node` to the number of Neuro | |||||
| ```bash | ||||||
| torchrun --nproc_per_node=8 tensor_parallel_neuron.py | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
| ## Serving with vLLM-Omni | ||||||
|
|
||||||
| [vllm-omni-neuron](https://github.com/aws-neuron/vllm-omni-neuron) serves Diffusers pipelines on Neuron through | ||||||
| vLLM-Omni. Diffusers runs the pipeline, and the plugin handles device placement and compilation. | ||||||
|
|
||||||
| Neuron compiles static shapes, so declare the resolutions to serve up front. The server compiles them at startup and | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| rejects any other resolution. The number of inference steps isn't restricted. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ```bash | ||||||
| export VLLM_OMNI_NEURON_DIFFUSERS_RESOLUTIONS=256x256,512x512 | ||||||
| vllm serve <model-id> --omni --diffusion-load-format diffusers --dtype bfloat16 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice to use a real value here :)
Suggested change
|
||||||
| ``` | ||||||
|
|
||||||
| See the vllm-omni-neuron repository for installation and supported pipelines. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may also be nice to add what a sample request looks like so users know its good
Suggested change
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -426,6 +426,15 @@ def _unpack_latents_with_ids( | |
|
|
||
| return torch.stack(x_list, dim=0) | ||
|
|
||
| @staticmethod | ||
| def _prepare_timestep(timestep: torch.Tensor, latents: torch.Tensor) -> torch.Tensor: | ||
| """Broadcast the timestep to the batch and cast it to the latents dtype. | ||
|
|
||
| Kept as a tensor-only method so backends can compile it as its own region (e.g. libtorch-neuronx-lite, where | ||
| running this cast eagerly breaks the denoising loop). | ||
| """ | ||
| return timestep.expand(latents.shape[0]).to(latents.dtype) | ||
|
|
||
| def encode_prompt( | ||
| self, | ||
| prompt: str | list[str], | ||
|
|
@@ -838,7 +847,7 @@ def __call__( | |
|
|
||
| self._current_timestep = t | ||
| # broadcast to batch dimension in a way that's compatible with ONNX/Core ML | ||
| timestep = t.expand(latents.shape[0]).to(latents.dtype) | ||
| timestep = self._prepare_timestep(t, latents) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually don't do one-liner methods like this and prefer inlining them as much as possible for better readability. |
||
|
|
||
| latent_model_input = latents.to(self.transformer.dtype) | ||
| latent_image_ids = latent_ids | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -504,6 +504,16 @@ def _get_raw_image_size(image: PipelineImageInput) -> tuple[int, int]: | |
|
|
||
| raise ValueError(f"Unsupported image type: {type(image)}") | ||
|
|
||
| @staticmethod | ||
| # Copied from diffusers.pipelines.flux2.pipeline_flux2_klein.Flux2KleinPipeline._prepare_timestep | ||
| def _prepare_timestep(timestep: torch.Tensor, latents: torch.Tensor) -> torch.Tensor: | ||
| """Broadcast the timestep to the batch and cast it to the latents dtype. | ||
|
|
||
| Kept as a tensor-only method so backends can compile it as its own region (e.g. libtorch-neuronx-lite, where | ||
| running this cast eagerly breaks the denoising loop). | ||
| """ | ||
| return timestep.expand(latents.shape[0]).to(latents.dtype) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
|
||
| # Copied from diffusers.pipelines.flux2.pipeline_flux2_klein.Flux2KleinPipeline.encode_prompt | ||
| def encode_prompt( | ||
| self, | ||
|
|
@@ -1173,7 +1183,7 @@ def __call__( | |
|
|
||
| self._current_timestep = t | ||
| # broadcast to batch dimension in a way that's compatible with ONNX/Core ML | ||
| timestep = t.expand(latents.shape[0]).to(latents.dtype) | ||
| timestep = self._prepare_timestep(t, latents) | ||
|
|
||
| latent_model_input = torch.cat([latents, condition_image_latents], dim=1) | ||
| img_ids = combined_image_ids | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,10 +26,6 @@ | |
| from accelerate import init_empty_weights | ||
| from accelerate.hooks import add_hook_to_module, remove_hook_from_module | ||
|
|
||
| if is_flashinfer_available(): | ||
| import flashinfer | ||
|
Comment on lines
-29
to
-30
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like an unrelated change to me. |
||
|
|
||
|
|
||
| FP8_MAX = 448.0 | ||
| E2M1_MAX = 6.0 | ||
| NVFP4_BLOCK = 16 | ||
|
|
@@ -217,6 +213,8 @@ def __init__(self, in_features, out_features, bias=True, compute_dtype=None, dev | |
|
|
||
| def forward(self, inputs: torch.Tensor) -> torch.Tensor: | ||
| if inputs.is_cuda and is_flashinfer_available() and torch.cuda.get_device_capability(inputs.device)[0] >= 10: | ||
| import flashinfer | ||
|
|
||
| x = inputs.reshape(-1, self.in_features).to(torch.bfloat16).contiguous() | ||
| x_q, x_scale = flashinfer.nvfp4_quantize( | ||
| x, (1.0 / self.input_scale).reshape(1), sfLayout=flashinfer.SfLayout.layout_128x4, do_shuffle=False | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.