# Memory-Efficient Batching for Time Series Transformer Training: A Systematic Evaluation
## 5 Experimental Setup and Evaluation
### Results and Analysis
#### 5.3.1 Memory Optimization Evaluation  
To understand the effect of our view-based sliding-window batching techniques on different dataset parameters, we measured peak memory usage per batch while varying these dataset parameters. We conducted memory usage comparisons when increasing the number of features, batch sizes, and sequence lengths. **(1) Number of features:** For this particular experiment, we fixed the size of the batches to 500 samples and the sequence length of 1000 time steps. We compare the memory usage of each batch of data between two variants of our GPU-optimized sliding-window technique and the original PyTorch's tensor stacking baseline. We varied the number of features to create seven datasets with features ranging from 10-5000 to mimic real-world time series data in different industries and demonstrate the benefit and scalability of our approach. The experiment results and memory reduction percentages are displayed in Figure 8. Figure 8a displays the GPU memory usage to accommodate each batch of tensors for the training iterations. The \(x\)-axis represents each dataset with an increasing number of features. The \(y\)-axis shows the peak memory usage measured in gigabytes (GB). The results are plotted on a logarithmic scale for visualization purposes. As the number of features increases, the memory usage for each batch also increases for all measured approaches as shown in Figure 8a. However, both variants of our GPU-optimized approach (labeled \"Optimized\" and \"Optimized in memory\"), used less GPU memory than the default PyTorch tensor stacking approach (labeled \"Original\") across all seven benchmarked datasets. The 'preload' variant of our optimization (labeled \"Optimize in memory\") consumes more memory than the 'per-batch' optimization variant (labeled \"Optimized\") because all the raw data are transferred into the GPU memory for the \"preload\" variant, but only a batch worth of data is transferred for the \"per-batch\" optimizationvariant. Our optimizations reduced the memory usage by 98% and 99% on average for the \"preload\" and \"per-batch\" variants, respectively, as shown in Figure 8b. **(2) Batch size:** We varied the size of each batch of data ranging from 100 to 1000 samples. The sequence length was 1000 time steps and the dataset contained 500 time series features. The experiment results and memory reduction percentages are displayed in Figure 9. Figure 9b displays the GPU memory usage to accommodate each batch of tensors for the training process. The \(x\)-axis represents each dataset with increasing batch sizes. The \(y\)-axis shows the memory usage measured in gigabytes (GB). The results are plotted on a logarithmic scale. As the number of samples per batch increases, the memory usage for each batch also increases linearly for the baseline and our \"per-batch\" optimization variant (labeled \"Optimize\"). This is because the system has to transfer an increasing amount of data per batch. However, the difference in memory usage between these two approaches is evident. On the contrary, our optimization variant labeled \"Optimize in memory\" has a constant memory usage throughout the experiment even with an increase in the batch size. This is because this variant preloaded all the data into GPU memory and only created views from this data object. The size of the raw data was the same across all measured batch sizes. Therefore, the changes in the batch size are negligible during batch formation. Our  
Figure 8: Memory usage—increasing number of features. (**a**) Memory usage per batch; (**b**) memory reduction percentage. Figure 9: Memory usage—increasing batch size. (**a**) memory usage per batch; (**b**) memory reduction percentage. optimizations reduced the memory usage by 98% and 99% on average for the \"preload\" and \"per-batch\" variants, respectively, as shown in Figure 9b. **(3) Sequence length:** Similar to the previous experiment, here we varied the sequence length (look-back window) ranging from 100 to 5000 for each data sample and measured the memory usage.