News
NVIDIA Megatron Core Optimizes Market Data for AI Forecasting
NVIDIA Megatron Core streamlines market data preprocessing and AI model training for financial forecasting, enabling scalable transformer-based analysis.
NVIDIA has introduced a streamlined approach to preparing financial market data for AI-based forecasting using its open-source library, Megatron Core. This GPU-optimized framework enables the efficient training of transformer models at scale, addressing the complexities of processing high-frequency trading data.
Streamlining Market Data Preprocessing
Market data, which arrives as a continuous stream of trades and quotes timestamped to the microsecond, is first aggregated into "bars"—rows containing price, volume, and other statistics for each instrument over a specific time unit. NVIDIA’s preprocessing pipeline converts these intraday market bars into model-ready tensors, grouping consecutive bars into patches and sliding fixed-length context windows over them. This ensures that the data is consistent and ready for model training and inference.
The preprocessing script supports Parquet files with columns such as Symbol, Date, Timestamp, Close, and Volume. It derives within-day log returns and log volumes while excluding overnight gaps. Each patch retains its constituent features, and an instrument ID is included to help the model learn instrument-specific behaviors within shared parameters.
Training Transformer Models with Megatron-LM
Megatron Core integrates with the Megatron-LM GitHub repository, which provides preconfigured training scripts for financial time-series forecasting. Researchers can train models to predict returns and trading volumes across multiple horizons using a shared forecasting framework. The pipeline separates the data interface from the model architecture, allowing users to experiment with different model designs, optimizers, and training durations while reusing the prepared datasets.
The framework also incorporates temporal safeguards to prevent data leakage and forward-looking bias. For example, it splits data by date with embargo periods and computes per-horizon target statistics exclusively from the training split.
Flexible Forecasting Capabilities
NVIDIA’s approach supports both point and interval forecasts, enabling researchers to study short-term market behavior, trading activity, or execution timing. Forecast horizons can be defined in observation steps or patches, with targets represented as either point values (e.g., future returns and volumes) or cumulative values (e.g., summed log returns and total volumes over an interval).
For example, a one-minute bar with a five-step horizon corresponds to a five-minute forecast. The preprocessing pipeline records metadata such as patch size, context length, and forecast horizons, ensuring reproducibility and consistency across experiments.
Implementation and Next Steps
To implement this workflow, users can preprocess market-bar data using the provided script and then train models with Megatron-LM. The example command for preprocessing includes options for patch length, context length, and forecast horizons:
python examples/financial_timeseries/preprocessing.py \ --data-dir /data/bars --out-dir /data/tensors \ --patch-len 8 --context-len 32 --window-stride 16 \ --time-units-per-day 390 --horizons 1,2,5,15 \ --target-mode cumulative --no-allow-overnight-targets
Once preprocessing is complete, the training process can be initiated with a small model to validate the pipeline:
torchrun --nproc_per_node=4 -m examples.financial_timeseries.pretrain_ts \ --ts-data-path /data/tensors --dataloader-type cyclic \ --num-layers 4 --hidden-size 256 --num-attention-heads 4 \ --seq-length 32 --max-position-embeddings 32 \ --micro-batch-size 64 --global-batch-size 256 --train-iters 2000 \ --lr 3e-4 --min-lr 3e-5 --lr-decay-style cosine --lr-warmup-iters 100 \ --tokenizer-type NullTokenizer --bf16 \ --log-interval 50 --eval-interval 500 --eval-iters 20 \ --save /data/ckpt --save-interval 2000
This modular and scalable approach enables financial researchers to leverage advanced AI techniques for market forecasting, while maintaining flexibility in model design and data sources.