.. meta::
   :description: Tutorial for SGLang-Neuron. Generate a 480p video from a text prompt with Wan2.2-T2V-A14B and SGLang Diffusion on one AWS Trainium2 trn2.48xlarge instance.
   :keywords: SGLang, SGLang-Neuron, SGLang Diffusion, Wan2.2, Wan2.2-T2V-A14B, text to video, diffusion, AWS Neuron, Trainium2, Trn2, trn2.48xlarge
   :date-modified: 2026-11-16

.. _sglang-neuron-wan22-text-to-video-tutorial:

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 :ref:`SGLang-Neuron quickstart <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-Diffusers`` on 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 <https://github.com/sgl-project/sglang-neuron/blob/main/docs/model-recipes/wan22.md>`__.

Prerequisites
-------------

- A trn2.48xlarge instance with Docker Engine and the Neuron driver of Neuron SDK 2.33.0 (``aws-neuronx-dkms`` 2.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
------------------------

1. Set the variables. Replace the paths with directories on the host:

   .. code-block:: bash

      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

2. Download the checkpoint:

   .. code-block:: bash

      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:

.. code-block:: bash

   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:

.. code-block:: bash

   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:

.. code-block:: bash

   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:

.. code-block:: bash

   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 ``--rm`` option removes the files of the container when it stops, so write the output to a mounted directory.

For more problems and fixes, see :ref:`sglang-neuron-tshoot`.

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 serve`` and the OpenAI-compatible ``/v1/videos`` API. See the `Wan2.2 model recipe <https://github.com/sgl-project/sglang-neuron/blob/main/docs/model-recipes/wan22.md>`__.
- :ref:`SGLang-Neuron supported models <sglang-neuron-supported-models-ref>`
- :ref:`SGLang-Neuron configuration reference <sglang-neuron-configuration-ref>`

Further reading
---------------

- :ref:`What is SGLang-Neuron? <sglang-neuron-overview>`
- `Wan2.2 example in the sglang-neuron repository <https://github.com/sgl-project/sglang-neuron/tree/main/examples/wan22>`__
