---
title: "A linear programming approach for optimizing features in ML models"
description: "Choosing which ML features to admit under limited infrastructure capacity can be framed as an integer linear program that maximizes model gain subject to per-service capacity constraints."
url: "https://swe.quest/articles/a-linear-programming-approach-for-optimizing-features-in-ml-models-4a887cc3d592174d"
canonical: "https://engineering.fb.com/2021/07/29/data-infrastructure/linear-programming/"
source: "Meta Engineering"
published: "2021-07-29"
difficulty: "medium"
kind: "Case study"
reading_minutes: 8
tags: ["machine-learning","capacity-planning","algorithms","python","ads"]
---

# A linear programming approach for optimizing features in ML models

A post on [Meta Engineering](https://swe.quest/sources/meta.md), published 2021-07-29, 8 min read, Case study. Original: [https://engineering.fb.com/2021/07/29/data-infrastructure/linear-programming/](https://engineering.fb.com/2021/07/29/data-infrastructure/linear-programming/)

## Summary

Choosing which ML features to admit under limited infrastructure capacity can be framed as an integer linear program that maximizes model gain subject to per-service capacity constraints. Greedy picks by gain, or by gain per unit of storage, fall short once features consume several resources (storage, memory, CPU) and optional compression trades gain for capacity in another service. Meta's ads ranking team encodes these constraints with boolean selection variables in CVXPY. The same model is rerun across capacity values to quantify the marginal return on investing in each service and to map substitution tradeoffs between services, replacing a manual feature-approval process.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Capacity planning](https://swe.quest/tags/capacity-planning.md) (Reliability & operations)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Ads](https://swe.quest/tags/ads.md) (Domains)

## Prerequisites

- linear programming basics
- ML feature engineering ([easy posts on Machine learning](https://swe.quest/tags/machine-learning.md?difficulty=easy))
- NumPy/pandas

## Keywords

linear programming, CVXPY, NumPy, knapsack problem, Facebook ads ranking

## Related posts

- [Linear programming for fun and profit](https://swe.quest/articles/linear-programming-for-fun-and-profit-77f85e06bfe14840.md): Modal · 2025-05-07 · Medium · 8 min read · Capacity planning, Cost optimization, Algorithms, Cloud platforms, Serverless
  Modal provisions GPU and CPU capacity across multiple clouds with a "resource solver" that formulates demand, prices, availability and per-instance limits as a linear program.
- [Intelligent Delivery: Making Every Unit of Compute Serve Better Ads](https://swe.quest/articles/intelligent-delivery-making-every-unit-of-compute-serve-better-ads-e2f91280ba29b622.md): Meta Engineering · 2026-11-11 · Medium · 9 min read · Ads, Recommendations & ranking, Inference & serving, Capacity planning, AI agents
  Meta's Intelligent Delivery is an ML-driven layer that allocates serving compute across requests, models, hardware fleets and ranking stages by predicting the marginal utility of each unit of compute, adding about 10% ads ranking performance since 2017.
- [Turning Opportunistic AI Inference Capacity Into Better Ads Recommendations](https://swe.quest/articles/turning-opportunistic-ai-inference-capacity-into-better-ads-recommendations-a2893f4d3d62c2b4.md): Meta Engineering · 2026-10-12 · Medium · 10 min read · Ads, Inference & serving, Recommendations & ranking, Resilience, Capacity planning
  Meta aggregates locally idle inference capacity, stranded by peak provisioning, delivery timing, resource-ratio and accelerator-type mismatches, into a preemptible opportunistic pool used to improve ads recommendations.
- [Design Once, Deploy at Scale: Building a Template-Driven ML Ecosystem](https://swe.quest/articles/design-once-deploy-at-scale-building-a-template-driven-ml-ecosystem-45ef241053332201.md): Meta Engineering · 2026-11-18 · Easy · 8 min read · ML platforms, Recommendations & ranking, Ads, AI agents
  Meta standardized its fragmented ads ranking model fleet into a small set of Standard Model Templates (SMT).
- [Network hose: Managing uncertain network demand with model simplicity](https://swe.quest/articles/network-hose-managing-uncertain-network-demand-with-model-simplicity-31704bd2f44dbf3d.md): Meta Engineering · 2021-06-15 · Hard · 7 min read · Networking, Capacity planning, Datacenters, Algorithms
  Meta plans its backbone network capacity against per-data-center aggregate ingress/egress forecasts (the "network hose") instead of a pairwise traffic matrix.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
