---
title: camera_rope
---

<div class="python-reference">
<a id="fastvideo.models.dits.hyworld.camera_rope-functions"></a>
<a id="fastvideo.models.dits.hyworld.camera_rope"></a>

<h2 id="fastvideo.models.dits.hyworld.camera_rope.prope_qkv"><code>fastvideo.models.dits.hyworld.camera_rope.prope_qkv</code></h2>
<pre class="doc-signature"><code>prope_qkv(q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, *, viewmats: torch.Tensor, Ks: Optional&#91;torch.Tensor&#93;, patches_x: int = None, patches_y: int = None, image_width: int = None, image_height: int = None, coeffs_x: Optional&#91;Tuple&#91;torch.Tensor, torch.Tensor&#93;&#93; = None, coeffs_y: Optional&#91;Tuple&#91;torch.Tensor, torch.Tensor&#93;&#93; = None, mask: Optional&#91;torch.Tensor&#93; = None, kv_cache = None, is_cache: bool = False, **kwargs) -&gt; torch.Tensor</code></pre>
<p>Similar to torch.nn.functional.scaled_dot_product_attention, but applies PRoPE-style
positional encoding.</p>
<p>Currently, we assume that the sequence length is equal to:</p>
<pre><code>cameras * patches_x * patches_y
</code></pre>
<p>And token ordering allows the <code>(seqlen,)</code> axis to be reshaped into
<code>(cameras, patches_x, patches_y)</code>.</p>
<details><summary>Source</summary><pre><code>def prope_qkv(
    q: torch.Tensor,  # (batch, num_heads, seqlen, head_dim)
    k: torch.Tensor,  # (batch, num_heads, seqlen, head_dim)
    v: torch.Tensor,  # (batch, num_heads, seqlen, head_dim)
    *,
    viewmats: torch.Tensor,  # (batch, cameras, 4, 4)
    Ks: Optional&#91;torch.Tensor&#93;,  # (batch, cameras, 3, 3)
    patches_x: int = None,  # How many patches wide is each image?
    patches_y: int = None,  # How many patches tall is each image?
    image_width: int = None,  # Width of the image. Used to normalize intrinsics.
    image_height: int = None,  # Height of the image. Used to normalize intrinsics.
    coeffs_x: Optional&#91;Tuple&#91;torch.Tensor, torch.Tensor&#93;&#93; = None,
    coeffs_y: Optional&#91;Tuple&#91;torch.Tensor, torch.Tensor&#93;&#93; = None,
    mask: Optional&#91;torch.Tensor&#93; = None,
    kv_cache=None,
    is_cache: bool = False,
    **kwargs,
) -&gt; torch.Tensor:
    &quot;&quot;&quot;Similar to torch.nn.functional.scaled_dot_product_attention, but applies PRoPE-style
    positional encoding.

    Currently, we assume that the sequence length is equal to:

        cameras * patches_x * patches_y

    And token ordering allows the `(seqlen,)` axis to be reshaped into
    `(cameras, patches_x, patches_y)`.
    &quot;&quot;&quot;
    # We&#x27;re going to assume self-attention: all inputs are the same shape.
    (batch, num_heads, seqlen, head_dim) = q.shape
    cameras = viewmats.shape&#91;1&#93;
    assert q.shape == k.shape == v.shape
    assert viewmats.shape == (batch, cameras, 4, 4)
    assert Ks is None or Ks.shape == (batch, cameras, 3, 3)
    # assert seqlen == cameras * patches_x * patches_y

    apply_fn_q, apply_fn_kv, apply_fn_o = _prepare_apply_fns_all_dim(
        head_dim=head_dim,
        viewmats=viewmats,
        Ks=Ks,
        patches_x=patches_x,
        patches_y=patches_y,
        image_width=image_width,
        image_height=image_height,
        coeffs_x=coeffs_x,
        coeffs_y=coeffs_y,
    )

    query = apply_fn_q(q)
    key = apply_fn_kv(k)
    value = apply_fn_kv(v)

    return query, key, value, apply_fn_o</code></pre></details>
</div>
