Your core intuition about training with variable memory sizes to enable generalization is sound, but you're walking into several fundamental tensions that will likely determine whether this approach succeeds or fails.
The most immediate issue is the representation collapse problem. When you train with random memory sizes, you're essentially asking your model to learn representations that are simultaneously optimal for vastly different capacity constraints. A model that learns to compress information aggressively for small memory sizes may develop fundamentally different internal representations than one that can afford to be more expansive. The question becomes: can a single set of parameters actually encode both strategies effectively, or will you end up with a compromise that's suboptimal for both regimes?
Your RBF kernel idea reveals a deeper architectural tension. You're proposing that taking the first n terms of an expanded representation should gracefully degrade performance, but this assumes the kernel basis functions have a natural ordering by importance. Real-world attention patterns rarely follow such clean hierarchies. The most critical information for a given context might require basis functions from anywhere in your expanded space, not just the "first n" terms.
The training dynamics present another critical challenge. During training, your model will see the same input with different memory constraints across iterations. This creates a peculiar optimization landscape where the model must learn to be simultaneously consistent (similar outputs for similar memory sizes) and adaptive (leveraging additional capacity when available). The gradient signals from these different configurations may conflict, potentially leading to unstable training or convergence to poor local minima.
For linear attention specifically, you're facing the fundamental expressivity-efficiency tradeoff. The state size directly determines the model's ability to maintain long-range dependencies. When you constrain this during training, you're not just limiting memory—you're fundamentally altering what patterns the model can learn to recognize and maintain. A model trained primarily on smaller state sizes may never learn to exploit the richer representational space available at larger sizes.
The generalization assumption itself deserves scrutiny. You suggest that networks with memory sizes 10000 and 10001 should behave similarly, but this assumes smooth scaling behavior. In practice, discrete jumps in memory size can lead to qualitatively different computational regimes, especially near critical thresholds where the model transitions from being memory-bound to computation-bound.
Finally, there's the evaluation complexity. How will you measure whether your approach actually works? The model's behavior at larger memory sizes will be fundamentally untested during training. You'll need to carefully consider what constitutes "successful generalization" and whether improved performance at larger sizes represents genuine capability enhancement or simply the model learning to ignore the additional capacity.
The essential difficulty you need to resolve is whether variable-capacity training can produce representations that are both robust across memory constraints and capable of effectively utilizing additional capacity when available. This is fundamentally a question about the geometry of your model's representational space and whether it can support this kind of structured scalability.