This document is relevant for: Trn2
Tutorial: Generate a video from text with Wan2.2#
Note
SGLang-Neuron is in public preview. Features, APIs, and supported models can change in later releases.
Applies to: trn2.48xlarge
Overview#
In this tutorial, you generate a 480p video from a text prompt with Wan2.2-T2V-A14B on one trn2.48xlarge instance. SGLang Diffusion runs the model on the Neuron platform of SGLang-Neuron. You run the Wan2.2 example script in the container image. The script generates one video and writes it to a directory on the host.
This tutorial takes approximately 45 minutes. Most of this time is the download of the checkpoint and the first compile of the programs.
Before you start#
Do the SGLang-Neuron quickstart first, to learn the container options and the compile cache. The quickstart uses a Trn3 instance. This tutorial uses a Trn2 instance, but the container options are the same.
Model details#
Checkpoint:
Wan-AI/Wan2.2-T2V-A14B-Diffuserson Hugging Face.Layout: 64 workers, one for each logical NeuronCore, as tensor parallelism 4 x classifier-free guidance (CFG) parallelism 2 x context parallelism 8.
Output: one video of 81 frames at 832 x 480.
VAE: the script sets
SGLANG_NEURON_WAN_VAE_PATCH_PARALLEL_SIZE=16, the patch parallelism of the variational autoencoder (VAE) for 480p. Other resolutions use other values. For the values, see the Wan2.2 model recipe.
Prerequisites#
A trn2.48xlarge instance with Docker Engine and the Neuron driver of Neuron SDK 2.33.0 (
aws-neuronx-dkms2.31.7.0 or later).A bash shell.
Internet access from the instance, to pull the image and download the checkpoint.
Three host directories: one for the checkpoints, one for the compile cache, and one for the output videos.
Approximately 130 GB of free disk space for the checkpoint.
Prepare your environment#
Set the variables. Replace the paths with directories on the host:
IMAGE=public.ecr.aws/neuron/pytorch-inference-sglang-neuron:v0.1.0-neuron-py314-sdk-2.33.0-ubuntu26.04 MODELS=/path/to/models CACHE=/path/to/cache OUT=/path/to/out
Download the checkpoint:
docker run --rm -v $MODELS:/models $IMAGE hf download Wan-AI/Wan2.2-T2V-A14B-Diffusers --local-dir /models/Wan2.2-T2V-A14B-Diffusers
Step 1: Start the container#
In this step, you start a container on one node, with a directory for the videos mounted at /out, and open a shell in it:
DEVICES=$(for d in /dev/neuron*; do printf -- '--device %s ' "$d"; done)
docker run -it --rm --name sglang --init --ipc=host --cap-add SYS_NICE $DEVICES \
-v $MODELS:/models:ro -v $CACHE:/cache -v $OUT:/out $IMAGE bash
This command is the one-node container command from the examples, with -v $OUT:/out added. It does not need the EFA devices or --network host.
Step 2: Generate the video#
In this step, you run the Wan2.2 example script in the container shell:
bash /opt/sglang-neuron/examples/wan22/run_generate.sh
The script runs sglang generate with the validated flags. It uses a default prompt and a default negative prompt. To use a different prompt, set PROMPT and NEGATIVE_PROMPT before the command:
PROMPT="<your prompt>" NEGATIVE_PROMPT="<your negative prompt>" bash /opt/sglang-neuron/examples/wan22/run_generate.sh
Arguments after the script name go to sglang generate.
Confirmation#
In the container shell, list the output file:
ls -la /out/t2v_480p.mp4 # the video: 81 frames at 832 x 480
The video is also in the $OUT directory on the host.
Common issues#
The script exits at start with
the compile cache ... was built from other NKI kernel sources. The cache directory belongs to a different image version. Give this image its own cache directory.The script fails with
Failed to load the backend extension: torch_neuronx. A volume is mounted at/workspace, or you started the script from/workspace. Mount your data at a different path, and run the script from a different directory.No video in the output directory on the host. The output directory is not mounted at
/out. The--rmoption removes the files of the container when it stops, so write the output to a mounted directory.
For more problems and fixes, see Troubleshooting: SGLang-Neuron.
Clean up#
Exit the container shell. The --rm option removes the container. The video stays in $OUT, and the compiled programs stay in $CACHE.
Next steps#
To serve many video requests, start a server with
sglang serveand the OpenAI-compatible/v1/videosAPI. See the Wan2.2 model recipe.
Further reading#
This document is relevant for: Trn2