Instamart’s Generative AI Forecasting: Scaling from Flat Forecasts to Deep Hierarchies
Authors : Sahib Majithia Satpalsingh Jaspalsingh Ghunia Mano Ranjith Kumar M
Instamart’s Generative AI Forecasting: Scaling from Flat Forecasts to Deep Hierarchies
Authors : Sahib Majithia Satpalsingh Jaspalsingh Ghunia Mano Ranjith Kumar M
Special thanks to Potturi Hemanth Sai Varma and Soumyajyoti Banerjee for their contributions throughout the project and Sunil Rathee for his guidance.

Introduction
The quick commerce industry has fundamentally redefined consumer expectations — from “delivery in days” to “delivery in minutes.” This shift is not merely an operational upgrade over traditional e-commerce; it represents a complete re-architecture of supply chain, inventory management, and fulfilment strategies. At the heart of this transformation lies a critical capability: demand forecasting.
Unlike e-commerce, where centralised warehouses and longer delivery windows provide natural buffers against demand uncertainty, quick commerce operates in a highly constrained, hyperlocal environment. Each micro-fulfillment center serves a narrow geographic cluster, with limited storage and an expectation of near-instant fulfillment. In such a setting, even marginal inaccuracies in demand estimation can cascade into significant business inefficiencies — lost sales due to stockouts, increased wastage, or suboptimal assortment decisions.
Improvements in forecasting accuracy unlock substantial gains across product availability, operational efficiency, and unit economics. This is why demand forecasting is a core strategic lever, enabling platforms to operate more efficiently while delivering a superior customer experience.
Forecasting in quick commerce spans multiple layers and use cases, ranging from granular SKU-level predictions for micro-fulfillment centre replenishment to aggregated warehouse forecasts that drive upstream procurement. This requires accounting for category-specific nuances like shelf life, the cost of waste versus missed sales, and product cannibalization. Simultaneously, platform-wide metrics — such as Orders per Day (OPD) — are vital for logistics and capacity planning.
In this blog, we deep dive into two of the most critical forecasting challenges within the quick commerce ecosystem:
1. Forecasting Warehouse SKU Demand
Demand forecasting for each category has its unique characteristics. For Fruits and vegetables (FnV), shelf lives shorter than lead times translate forecasting errors into immediate physical wastage or missed margins. “Fresh” SKUs, while lasting longer than procurement cycles, require aggressive discounting near expiration to avoid a zero-value state. For Packaged SKUs, errors primarily lead to operational inefficiencies, with under-forecasting causing stock outs and over-forecasting locking up significant working capital. This creates a spectrum where the penalty for inaccuracy shifts from direct product disposal in perishables to financial stagnation in packaged goods.

Table1: Comparison of Unique characteristics of different categories
2. Forecasting Orders per Day (OPD)
OPD forecasting is the primary signal used for rider fleet planning, dark store (fulfillment center) staffing, and last-mile capacity optimization. It captures aggregate demand intensity and exhibits extreme sensitivity to promotions and volatile external factors such as inclement weather and local events. Underestimation generates immediate capacity shortages, resulting in delayed deliveries and a degraded customer experience. Overestimation leads to systemic underutilization of expensive resources and inflated operational expenditure (OpEx). Accurate OPD forecasting ensures optimal resource synchronization, balancing service reliability with rigid cost control.
Our Forecasting Framework

Fig2: Forecasting Framework at Instamart
The following section outlines the framework of Instamart’s production system :
- Feature Engineering and Signal Preparation : The objective is to construct a clean, high-signal demand representation.
- Incorporate diverse signals: temporal patterns, rolling demand, pricing/promotions, events, weather, and store-level context. This enables cross-location generalisation essential for sparse hyperlocal forecasts, enabling scalability across stores and categories.
- Availability De-biasing : When SKUs are partially or fully out of stock, the recorded sales systematically understate demand, introducing availability bias. We learn the relationship between partial availability and true demand directly from data with full availability
- Modelling : Focuses on learning demand patterns across varying granularities.
- Empirical Model Selection: We evaluate a diverse library of architectures — ranging from tree-based models to Deep Learning frameworks like Temporal Fusion Transformers (TFT) and Foundation Models such as TimesFM. For any given use case, we identify and deploy the specific model that demonstrates the highest predictive accuracy.
- Incorporates hierarchical forecasting to exploit aggregation for variance reduction and improved stability.

Table2 : Comparison of different models in our model library
- Post-Processing :
- Guardrails : Enforce guardrails to bound forecasts within realistic ranges and prevent extreme predictions and ensure operational feasibility.
- Business Intelligence: The BI layer at Instamart refines the raw forecast by balancing the financial and operational impact of over-forecasting versus under-forecasting. Trade offs are taken based on cost of wastage versus missed sales, shelf life, events demand spikes etc.
This ensures that forecasts are precise at the modelling stage, and also aligned with downstream decision-making.
Modeling
TimesFM: A Foundation Model for Time Series
TimesFM redefines forecasting as a generative task by applying the token-based logic of Large Language Models to the numerical time-series data. While NLP models map discrete vocabulary to embeddings, TimesFM uses continuous tokenisation. It flattens temporal patches and projects them into a latent space, allowing the transformer to attend to “time tokens” just as LLMs attend to “word tokens.”

Table3: Architectural comparison of NLP and Time-series Transformers
How TimesFM Becomes a “Foundation” Model ?

Fig3: TimesFM Model Architecture
- Massive Scale and Heterogeneity: TimesFM is pretrained on an unprecedented corpus of ~100 billion time points. This dataset is intentionally diverse, combining synthetic data with real-world traces from retail, finance, weather, and energy.
- Multi-Frequency Mastery: Unlike classical models that are often tuned for a specific frequency (e.g., daily), TimesFM is trained across a spectrum of granularities — from minutely to monthly data. This allows the model to learn a unified temporal representation that recognizes varying periodicities and seasonal rhythms automatically. This is enabled through a frequency parameter conditioned training and prediction.
- Patched Time-Series Representation: Rather than processing individual time points, the model segments input data into fixed-length patches (typically 32 time steps). Each patch is treated as a single “token.” This reduces the total sequence length, significantly lowering the computational overhead required to train on large data.
- Causal Attention Mechanism: Utilising a GPT-style causal transformer, the model ensures that any prediction is strictly conditioned on past observations. This autoregressive structure allows for robust multi-horizon forecasting required across different use cases.
This allows the model to internalise distributional priors over time-series behavior, analogous to linguistic priors in LLMs. Hence, the model can generate forecasts for unseen time series without retraining, leveraging learned global temporal patterns.
Hierarchical Forecasting: A Variance Reduction Perspective
While foundation models enhance base predictions, hierarchical forecasting provides an orthogonal improvement by systematically addressing the noise inherent in granular data.
In Quick Commerce, demand at the SKU × Store level is often sparse and high-variance. Conversely, aggregated levels — such as SKU × Warehouse or Category × Region — act as natural variance-reduction mechanisms, offering more stable and learnable signals.
This framework leverages the “signal-to-noise” advantage of aggregation by modeling demand at higher levels and disaggregating predictions through structured allocation.

Fig4: Hierarchical forecasting: Granularity to Stability and Back
The Dual-Hierarchy Framework
Effective hierarchical forecasting [4] requires a clear distinction between business requirements and modelling strategy:
- Objective Hierarchy (Business Requirement): The fixed granularity at which the forecast is consumed (e.g., hourly demand per dark store for rider staffing).
- Prediction Hierarchy (Modelling Decision): The optimal level at which the model is trained. While the objective is fixed, the prediction level is a flexible choice designed to maximise signal strength.
Statistical Selection and Validation
To bridge these two hierarchies, we employ a rigorous selection process:
- Variance-Based Selection: The prediction hierarchy is identified by analysing the Coefficient of Variation (CoV) across candidate levels. A lower CoV signifies a more stable, high-signal representation, making it a superior candidate for model training. Other works also utilise methods such as spectral predictability [3]
- Disaggregation Logic: Forecasts generated at the prediction level are projected down to the objective level using historical allocation ratios.
- Stability Validation (KS Test): We utilise the Kolmogorov–Smirnov test to compare the distribution of allocation ratios between consecutive time periods (T and T+1); if no statistically significant difference is found, the ratios are deemed stable, confirming that historical proportions remain valid for future disaggregation.
By separating the prediction level from the objective level, this framework ensures the system learns from the most robust demand representations while delivering the granular outputs required for localised operations.
Further, we also observe that combined framework results in high relative improvement at higher aggregation level than granular hierarchies.

Table 4: Relative WMAPE gain of the TimesFM model + hierarchical improvements over baselines.
Warehouse SKU Forecasting:
Correcting Availability Bias for Demand:
Since recorded sales are a censored proxy of true demand, stockouts or partial availability suppress actual customer intent. If uncorrected for bias, this leads to systematic underestimation and propagates errors into downstream forecasting and procurement decisions.
While industry approaches for availability de-biasing [5] include heuristic scaling, censored demand models, and substitution-based methods.The localised nature of our supply chain introduces significant availability bias, necessitating a more sophisticated, data-driven approach at Instamart as follows :
- Training is restricted to fully available periods (availability = 1) to obtain unbiased demand
- Synthetic training samples are generated by simulating partial availability scenarios i.e masking sales after hour = h for the day.
- A model is trained to learn the mapping from observed sales under partial availability → true demand

Fig5: A simple cyclic model of how uncorrected sales data perpetuates stockouts
Since biased features cannot predict de-biased outputs, we de-bias both features and labels during training using the above method. This same logic is applied to features at inference to ensure predictions reflect true customer intent rather than stock constraints.
Defining the Forecasting Unit: Group SKU (GSKU)
At the SKU level, demand exhibits high volatility due to intra-category substitution and stockout-driven demand shifts. Closely related SKUs (e.g., variants within a product group) often cannibalise each other’s demand, introducing instability at the individual SKU level.
To address this, we introduce the concept of Group SKU (GSKU):
- Groups together functionally similar or substitutable SKUs
- Reduces variance by aggregating demand across related SKUs, hence improving signal stability for modelling
- Enhances availability and cross-selling, as demand can be fulfilled across interchangeable SKUs
While the algorithmic framework used to define these groups is essential to our process, we have omitted the technical details here to focus on the practical impact of GSKUs.

Fig6: Defining the Forecasting Unit: Group SKU (GSKU)
GSKU thus serves as a more stable and operationally meaningful unit for forecasting.
Hierarchical Modelling Strategy
The business requirement is to generate forecasts at the (SKU, warehouse) level. However, directly modelling at this granularity leads to high variance due to sparsity.
Using the hierarchical framework described earlier:
- Prediction Hierarchy Selection: Based on variance analysis (CoV), (GSKU, warehouse) was identified as a lower-variance, high-signal level.
- Modelling Approach: We generate forecasts at the (GSKU, warehouse) level using TimesFM (zero-shot, univariate setup). This leverages the model’s ability to generalise temporal patterns without heavy feature engineering, particularly effective in sparse regimes.
- Disaggregation Strategy: 14 day historic sales ratio of SKUs was validated for stability for disaggregating (GSKU, warehouse) demand into (SKU, warehouse).
Impact
This end-to-end design — comprising unconstrained demand signals, GSKU-level aggregation, foundation model-based forecasting, and hierarchical disaggregation — has resulted in a 21% , 38% and 24% relative improvement in warehouse forecasting accuracy for FnV, Fresh and Packaged categories respectively. .
OPD Forecasting:
The business objective in this case is to generate forecasts at the (Pod, Hour) level.
Hierarchical Modelling Strategy
Direct modelling at the (Pod, Hour) level introduces significant noise due to high-frequency variability and sparse signal. Applying the hierarchical framework:
- Prediction Hierarchy Selection: Based on variance characteristics, (Pod, Day) was identified as a more stable level for modeling, offering stronger signal quality compared to hourly data.
- Modelling Approach: Forecasts are generated at the (Pod, Day) level using TimesFM (zero-shot setup with covariates). Incorporating covariates enables the model to capture systematic demand drivers such as temporal patterns, events, and other external signals, improving forecast fidelity at the aggregate level.
- Covariate Handling in TimesFM (xreg modes): TimesFM incorporates external regressors (xreg) using a Ridge Regression layer, which works alongside the transformer-based forecast. It supports two main integration strategies: - xreg + TimesFM (Default) — A linear model is first fit on the target series using covariates.Residuals (unexplained components) are then modeled using TimesFM.
- TimesFM + xreg — TimesFM first generates a baseline forecast.A linear model is then applied on the residuals to adjust the forecast using covariates.
- Disaggregation to Hourly Level: Daily forecasts are disaggregated to (Pod, Hour) using historical intra-day demand distributions, which exhibit strong stability when conditioned on day-of-week.
Impact
Combining stable aggregation for modelling, covariate-aware foundation models, and structured disaggregation — resulted in:
- 7.5% relative improvement in WMAPE
- 50% reduction in end-to-end runtime, compared to the previous TFT-based system.
Conclusion and Future Work
This work demonstrates that meaningful improvements do not come from modelling alone, but from a cohesive framework — combining corrected demand signals, principled hierarchy design, and modern foundation models.
The integration of TimesFM and hierarchical forecasting enables a shift from noisy, high-variance predictions to stable, high-signal forecasts, while still meeting fine-grained business requirements at Instamart through structured disaggregation
To further evolve our forecasting stack, we are exploring several high-impact technical frontiers:
- Few-Shot and Fine-Tuning with TimesFM: While zero-shot performance is strong, leveraging few-shot adaptation and targeted fine-tuning can further improve accuracy in domain-specific settings, particularly for sparse or rapidly evolving demand patterns.
- Advanced Hierarchical Forecasting Techniques: Incorporating state-of-the-art reconciliation methods (e.g., probabilistic and optimization based approaches as explored in modern hierarchical forecasting frameworks) can improve coherence and optimality across levels, beyond deterministic disaggregation.
Ultimately, the goal is to continue narrowing the gap between predictive intelligence and operational reality. A reliable and precise data foundation enables a seamless, high-performance supply chain that helps meet the “instant” expectations of the modern consumer.
References:
- TimesFM: Das, A., et al. (2023). A decoder-only foundation model for time-series forecasting. arXiv:2310.10688
- TFT: Lim, B., et al. (2021). Temporal fusion transformers for interpretable multi-horizon time series forecasting. International Journal of Forecasting. arXiv:1912.09363
- Forecastability: Wang, R., et al. (2025). Time Series Forecastability Measures. arXiv:2507.13556
- HierarchicalForecast: Olivares, K. G., et al. (2022). HierarchicalForecast: A Reference Framework for Hierarchical Forecasting in Python. Nixtla Documentation
- FreshRetailNet-50K: Wang, Y., et al. (2025). FreshRetailNet-50K: A Stockout-Annotated Censored Demand Dataset… arXiv:2505.16319
메타데이터
- post_id
- 89357682fbb5
- slug
- instamarts-generative-ai-forecasting-scaling-from-flat-forecasts-to-deep-hierarchies-89357682fbb5
- url
- https://medium.com/swiggy-bytes/instamarts-generative-ai-forecasting-scaling-from-flat-forecasts-to-deep-hierarchies-89357682fbb5
- canonical_url
- https://medium.com/swiggy-bytes/instamarts-generative-ai-forecasting-scaling-from-flat-forecasts-to-deep-hierarchies-89357682fbb5
- author_url
- https://medium.com/@sahib.majithia1
- status
- ok
- fetched_at
- 2026-06-18 00:10:23