Repository: huggingface/diffusers

Issue:
StableVideoDiffusionPipeline returns a list instead of np.ndarray for output_type="np"
### Describe the bug

The [comments](https://github.com/huggingface/diffusers/blob/4497b3ec982978eca99895ed1429addde4a84fff/src/diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py#L64) for StableVideoDiffusionPipelineOutput (which is returned by the `__call__()` function of StableVideoDiffusionPipeline) indicate that `np.ndarray` is one of the possible return types for the `frames` field but when I set `output_type="np"` for `__call__()` the `frames` field is a list of `np.ndarray`.

I think the problem is that the output of the `tensor2vid()` call [here](https://github.com/huggingface/diffusers/blob/4497b3ec982978eca99895ed1429addde4a84fff/src/diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py#L534) is a list and not a `np.ndarray`. I have a local commit that uses `np.stack()` to convert the list to a `np.ndarray` that I plan to push up as a PR shortly.

### Reproduction

```
from diffusers import StableVideoDiffusionPipeline
from diffusers.utils import load_image
import torch
import time

repo_id = "stabilityai/stable-video-diffusion-img2vid-xt"
cache_dir = "./cache"
pipeline = StableVideoDiffusionPipeline.from_pretrained(
    repo_id, cache_dir=cache_dir, variant="fp16", torch_dtype=torch.float16
)
pipeline.to("cuda")

# Load the conditioning image
image = load_image(
    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/svd/rocket.png"
)
image = [image.resize((1024, 576))]
image *= 2

generator = torch.manual_seed(42)

frames = pipeline(
    image,
    decode_chunk_size=8,
    generator=generator,
    output_type="np",
).frames

print(type(frames))
print(frames.shape)
```

### Logs

```shell
Loading pipeline components...: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 11.34it/s]
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 25/25 [01:33<00:00,  3.72s/it]
<class 'list'>
Traceback (most recent call last):
  File "/home/user/ai-worker/jobs/containers/svd-xt-film/test_svd.py", line 33, in <module>
    print(frames.shape)
          ^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'shape'
```


### System Info

- `diffusers` version: 0.25.0
- Platform: Linux-5.4.0-166-generic-x86_64-with-glibc2.31
- Python version: 3.11.7
- PyTorch version (GPU?): 2.1.2+cu121 (True)
- Huggingface_hub version: 0.20.2
- Transformers version: 4.36.2
- Accelerate version: 0.25.0
- xFormers version: 0.0.23.post1
- Using GPU in script?: Nvidia RTX 4090

### Who can help?

@patil-suraj @patrick


Discussion:

Resolving patch:
diff --git a/src/diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py b/src/diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py
--- a/src/diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py
+++ b/src/diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py
@@ -52,6 +52,9 @@ def tensor2vid(video: torch.Tensor, processor, output_type="np"):
 
         outputs.append(batch_output)
 
+    if output_type == "np":
+        return np.stack(outputs)
+
     return outputs
 
 


Test patch:
diff --git a/tests/pipelines/stable_video_diffusion/test_stable_video_diffusion.py b/tests/pipelines/stable_video_diffusion/test_stable_video_diffusion.py
--- a/tests/pipelines/stable_video_diffusion/test_stable_video_diffusion.py
+++ b/tests/pipelines/stable_video_diffusion/test_stable_video_diffusion.py
@@ -185,6 +185,23 @@ def test_inference_batch_single_identical(
     def test_inference_batch_consistent(self):
         pass
 
+    def test_np_output_type(self):
+        components = self.get_dummy_components()
+        pipe = self.pipeline_class(**components)
+        for component in pipe.components.values():
+            if hasattr(component, "set_default_attn_processor"):
+                component.set_default_attn_processor()
+
+        pipe.to(torch_device)
+        pipe.set_progress_bar_config(disable=None)
+
+        generator_device = "cpu"
+        inputs = self.get_dummy_inputs(generator_device)
+        inputs["output_type"] = "np"
+        output = pipe(**inputs).frames
+        self.assertTrue(isinstance(output, np.ndarray))
+        self.assertEqual(len(output.shape), 5)
+
     def test_dict_tuple_outputs_equivalent(self, expected_max_difference=1e-4):
         components = self.get_dummy_components()
         pipe = self.pipeline_class(**components)