File size: 1,055 Bytes
6494534
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

try:
    import torch
    from torch import nn
except ImportError:  # pragma: no cover
    torch = None
    nn = None


class ChartEncoder(nn.Module if nn is not None else object):
    """Encode a chart summary into a compact CTT chart token.

    The first implementation uses exported numeric chart summaries such as the
    base action chunk. When visual-language embeddings are exported, the same
    module can consume them without changing the CTT operator interface.
    """

    def __init__(self, input_dim: int, hidden_dim: int = 128, output_dim: int = 64) -> None:
        if nn is None:  # pragma: no cover
            raise ImportError("ChartEncoder requires torch")
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(input_dim, hidden_dim),
            nn.ReLU(),
            nn.Linear(hidden_dim, output_dim),
            nn.LayerNorm(output_dim),
        )

    def forward(self, chart_features: "torch.Tensor") -> "torch.Tensor":
        return self.net(chart_features)