import torch
import torch.nn as nn


class Model(nn.Module):
    def __init__(self, eps=1e-12):
        super().__init__()
        self.eps = eps

    def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
        combined = torch.cat([x, y], dim=0)
        global_min = combined.min(dim=0).values
        global_max = combined.max(dim=0).values

        ranges = global_max - global_min

        ranges = torch.clamp(ranges, min=self.eps)

        diff = torch.abs(x - y)
        return (diff / ranges).mean(dim=1)


batch_size = 128
feature_dim = 512


def get_inputs():
    x = torch.randn(batch_size, feature_dim, dtype=torch.float32)
    y = torch.randn(batch_size, feature_dim, dtype=torch.float32)
    return [x, y]


def get_init_inputs():
    return [1e-12]