Run this model with HF Jobs
Run Agnes-AI/Agnes-Video-H3-MoE on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Agnes-AI/Agnes-Video-H3-MoE. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Agnes-AI/Agnes-Video-H3-MoE on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
File size: 2,563 Bytes
2594d73 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import torch
from torch import nn
class LTX25AttentionPooler(nn.Module):
def __init__(self, hidden_dim: int = 256, num_queries: int = 1, num_heads: int = 4):
super().__init__()
self.hidden_dim = hidden_dim
self.num_queries = num_queries
self.query_tokens = nn.Parameter(torch.randn(num_queries, hidden_dim) * 0.02)
self.cross_attn = nn.MultiheadAttention(
embed_dim=hidden_dim,
num_heads=num_heads,
batch_first=True,
)
def forward(self, tokens: torch.Tensor) -> torch.Tensor:
queries = self.query_tokens.unsqueeze(0).expand(tokens.shape[0], -1, -1)
pooled, _ = self.cross_attn(queries, tokens, tokens, need_weights=False)
return pooled
class LTX25DurationHead(nn.Module):
def __init__(
self,
video_cross_attention_dim: int = 4096,
audio_cross_attention_dim: int = 2048,
pooler_hidden_dim: int = 256,
num_queries: int = 1,
num_pooler_heads: int = 4,
mlp_hidden: int = 256,
):
super().__init__()
self.pooler_hidden_dim = pooler_hidden_dim
self.video_input_proj = nn.Linear(video_cross_attention_dim, pooler_hidden_dim)
self.video_modality_emb = nn.Parameter(torch.randn(pooler_hidden_dim) * 0.02)
self.audio_input_proj = nn.Linear(audio_cross_attention_dim, pooler_hidden_dim)
self.audio_modality_emb = nn.Parameter(torch.randn(pooler_hidden_dim) * 0.02)
self.attention_pooler = LTX25AttentionPooler(pooler_hidden_dim, num_queries, num_pooler_heads)
self.mlp_hidden = nn.Linear(pooler_hidden_dim * num_queries, mlp_hidden)
self.mlp_out = nn.Linear(mlp_hidden, 1)
def forward(
self,
video_tokens: torch.Tensor | None = None,
audio_tokens: torch.Tensor | None = None,
) -> torch.Tensor:
if video_tokens is None and audio_tokens is None:
raise ValueError("LTX25DurationHead.forward requires video_tokens and/or audio_tokens.")
token_groups = []
if video_tokens is not None:
token_groups.append(self.video_input_proj(video_tokens) + self.video_modality_emb)
if audio_tokens is not None:
token_groups.append(self.audio_input_proj(audio_tokens) + self.audio_modality_emb)
pooled = self.attention_pooler(torch.cat(token_groups, dim=1))
hidden = torch.nn.functional.gelu(self.mlp_hidden(pooled.reshape(pooled.shape[0], -1)), approximate="tanh")
return self.mlp_out(hidden).squeeze(-1).exp()
|