Library / SDK
Optimization-AI/LibAUC avatar
Optimization-AI/LibAUC

LibAUC 2.0: Optimizing X-Risks in PyTorch Without Rewriting Your Training Loop

LibAUC: A Deep Learning Library for X-Risk Optimization

324 stars43 forksPythonMIT

At a glance

What is it?
LibAUC is an MIT-licensed Python library that provides surrogate losses and matching optimizers for AUROC, AUPRC, partial AUC, NDCG and global contrastive objectives. The core judgement: it is worth adopting when your metric is a ranking or threshold-free measure, and it is the wrong tool when plain cross-entropy already matches your deployment objective.
Who is it for?
Adopt LibAUC if your evaluation metric is AUROC, AUPRC, partial AUC, NDCG or a global contrastive objective and you are training in PyTorch, because the library supplies the loss and the optimizer that goes with it rather than leaving you to derive the update yourself. Do not adopt it if cross-entropy or a standard ranking loss already matches your deployment metric, or if you cannot accept a second optimizer object with its own update_regularizer call in the training loop.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 25 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

The gap LibAUC fills: metrics that gradient descent cannot touch directly

AUROC and AUPRC are computed over pairs of examples, not over individual examples. Sorting by score and counting concordant pairs is a piecewise-constant operation, so the gradient is zero almost everywhere and undefined at the ties. The standard workaround is to train with cross-entropy and hope the ranking metric follows. LibAUC takes the other route: it supplies surrogate losses that are differentiable, and it supplies optimizers that account for the structure those surrogates create. The README describes this as "a unified framework to abstract the optimization of many compositional loss functions", covering surrogate losses for AUROC, AUPRC/AP and partial AUROC for classification of imbalanced data, surrogate losses for NDCG and top-K NDCG for learning to rank, and global contrastive losses for representation learning. The audience is narrow and specific: researchers and engineers who already train in PyTorch and who have measured that their deployment metric is one of these X-risks. If your metric is accuracy, this library has nothing to offer you.

What the training loop actually looks like

The README gives a worked example for AUROC. You import AUCMLoss from libauc.losses and PESG from libauc.optimizers, then instantiate both. The loop itself is ordinary PyTorch: move data and targets to CUDA, run the model, apply torch.sigmoid to the logits, call the loss, zero the gradients, backward, step. What differs is the line after the step. The example calls optimizer.update_regularizer() once per iteration, with the comment "update internal parameters". That call is the visible sign of the mechanism underneath. Surrogate X-risk losses carry a dual variable or an internal state that has to be advanced alongside the network weights, and the optimizer owns that state. Drop the call and the loop still runs; the objective it is optimizing is no longer the one you selected. This is the single most important thing to understand before adopting the library, and it is easy to miss because the surrounding code looks like every other training script you have written.

Installation and the version boundary at 2.0

Two install paths are documented. From PyPI: pip install -U libauc. From source: git clone the repository, cd into LibAUC, then pip install . The PyPI badge in the README lists a Python version range, and a separate badge pins PyTorch to 2.0. That pin is the first thing to check against your environment, because a PyTorch major version mismatch is the most common reason a library like this fails at import rather than at runtime. LibAUC 2.0.0 was released on 2026-05-29, roughly twenty-one months after 1.4.0. The release notes listed in the README describe the 2.0 additions: a new LibAUC Trainer, distributed training support for all optimizers, integration with Hugging Face models, new optimizers for extreme classification and two-way partial AUC optimization, expanded tutorials, and improved support for resume training. If you are on 1.4.0, treat the upgrade as a migration, not a patch. The Trainer and the distributed support are new surfaces, and resume training changed.

Losses and optimizers are paired, and the pairing is not optional

The tutorial list in the README maps each objective to its own example: AUCMLoss for AUROC, APLoss for AUPRC, CompositionalAUCLoss, pAUCLoss for partial AUC, MIDAMLoss, NDCGLoss, and GCLoss in both unimodal and bimodal variants. Each of those losses has an optimizer designed for it. PESG appears in the AUROC example; the contrastive losses have their own. This is a departure from the usual PyTorch pattern where you can pair any loss with Adam and get a reasonable result. The reason is that these surrogates are not sums over independent examples. A compositional loss couples examples within a batch, so the gradient estimate depends on batch composition and on the accumulated dual state. Substituting Adam removes the mechanism that makes the surrogate a valid proxy for the X-risk. Practically, this means LibAUC is not a drop-in loss replacement you can slot into an existing training script that uses Adam. It is a paired loss-and-optimizer system.

Where LibAUC is the wrong choice

The library optimizes a proxy. The proxy is chosen so that descending on it tends to improve the X-risk, but the two are not identical, and the gap between them is not quantified anywhere in the material available here. If your deployment decision uses a fixed threshold rather than a ranking, AUROC is the wrong metric to optimize in the first place, and a calibrated cross-entropy model will serve you better. The second limitation is the batch coupling. Because these losses operate over pairs or over the full batch, small batch sizes give noisy gradient estimates, and the memory cost per step is higher than a pointwise loss at the same batch size. The README does not state a minimum batch size, so this has to be measured on your own hardware. Third, the internal state means checkpointing is not just saving model.state_dict(). If you resume from a checkpoint without restoring the optimizer's accumulated state, the run continues from a different point in the optimization than the one you saved. The 2.0 release notes mention improved support for resume training, which suggests this was a known rough edge in earlier versions. Verify the current behaviour against the release notes before relying on it.

How this differs from metric-learning and ranking libraries

PyTorch Metric Learning and the various triplet and contrastive loss collections take a pairwise approach: they construct positive and negative pairs, apply a margin or a temperature, and average the per-pair losses. The batch is a sampling device. LibAUC's compositional formulation treats the batch as the domain over which the X-risk is estimated, and the optimizer maintains a running estimate that carries across steps. That is a real architectural difference, not a naming one. It means the two families fail differently. Pairwise libraries are sensitive to how you mine negatives; LibAUC is sensitive to batch size and to whether update_regularizer is called. It also means you cannot port a triplet-loss training script to LibAUC by swapping the loss class. The GCLoss examples for contrastive learning are the closest point of contact, and even there the README presents them as their own pipeline with their own optimizer rather than as a substitute for an existing contrastive loss.

Maintenance, licensing and what to check before you commit

LibAUC is MIT-licensed, which permits commercial use, modification and redistribution provided the copyright notice and permission notice are retained. That is the most permissive common option and imposes no copyleft obligation on your own code. This is a description of the licence text, not legal advice; your counsel should review it if the library ships inside a product. On maintenance: the repository is not archived, the last push recorded is 2026-08-21, and the release cadence shows three tagged versions with a long gap between 1.4.0 in August 2024 and 2.0.0 in May 2026. The README's news section documents bug fixes in datasets/folder.py, in the all_gather communication inside GCLoss_v1, and in the margin parameter of AUCM loss and MultiLabelAUCM loss. That last one is worth reading closely: the note says the margin was missed in the original calculation, which "might cause the loss to be negative", and that it "does not affect the learning as the updates are not affected by this". A reported loss value that can go negative without affecting the update is exactly the kind of detail that makes a logged metric hard to interpret. If you monitor loss curves for debugging, know that the number you log may not be the quantity driving the step. Before adopting, run the AUROC example on your own data loader, confirm the PyTorch 2.0 pin matches your environment, and check the 2.0 release notes for the resume-training and checkpoint format details.

Editorial conclusion

Adopt LibAUC if your evaluation metric is AUROC, AUPRC, partial AUC, NDCG or a global contrastive objective and you are training in PyTorch, because the library supplies the loss and the optimizer that goes with it rather than leaving you to derive the update yourself. Do not adopt it if cross-entropy or a standard ranking loss already matches your deployment metric, or if you cannot accept a second optimizer object with its own update_regularizer call in the training loop. Before committing, verify the PyTorch version pinned by your environment against the 2.0 requirement in the badge, run the AUROC example end to end on your own data loader, and confirm the checkpoint format from the 2.0 release notes if you intend to resume training.

Official sources

  1. License: MIT
  2. Optimization-AI/LibAUC on GitHub
  3. Project website
  4. README
  5. Releases
Community notes

Community notes