Shop is live

We build Workstation AI machines for websites, AI agents, and LLM training — configure and buy online.

Get Trade Prices
AI Products
AI LabsOpenAI AgentsClaude AgentsGrok BotWorkstation AI native CRMMarketingAll Products
AI Solutions
Applied AIAI AgentsGenerative AIAI AutomationAI UpskillingAI SME PackagesEnterprise AI LabAI WorkstationsNVIDIA Hardware & SoftwareNVIDIA Accelerated ComputingPrivate AIGPU Private CloudGPU ClustersEdge AIAI by Industry
AI Services
Platform ModernisationDigital EngineeringData Foundations & AIAutonomous OperationsAI ConsultancyDevOps AutomationCyber SecuritySoftware DevelopmentAgent BuildingMLOps SetupGPU LeasingGPU Private Cloud
About Us
CompanyOur StoryPartnersCustomer Stories
AI Data Centres
AI Data CentresGPU Private CloudGPU ClustersGPU Leasing
AI InsightsJev seriesBenchmark LabModel selection
Technical Notes
Documentation
Linux OSUbuntuRed Hat Enterprise LinuxSUSE LinuxAlpine LinuxDebian, Rocky & AlmaLinux
AI Cloud PlatformsAWS & Amazon BedrockGoogle Cloud & Vertex AIMicrosoft Azure & AI FoundryGPU clouds & marketplaces
Private AI Data CentresFor law firmsFor accounting firmsOn-premises platformsFully secured cloud
ToolsRing PromoterJobshout
News
Blog
Contact UsSign in

AI workstations, AI Multi Agentic Software, GPU infrastructure, and intelligent agent solutions for modern businesses.

Contact Us

AI Solutions

Applied AIAI AgentsGenerative AIAI AutomationAI UpskillingAI SME PackagesEnterprise AI LabAI by Industry

Products

All ProductsWorkstation AI native CRM & ERPMarketingOpenAI AgentsRing PromoterJobshout

Company

About UsCompanyAI Data CentresWhy WorkstationPartnersCustomer StoriesPricingContactTenthMatrix

Resources

AI InsightsTechnical NotesDocumentationLinux OSAI Cloud PlatformsPrivate AI Data CentresBlogSearchSitemap
UK Head Office
77-79 Marlowes, Hemel Hempstead HP1 1LFDirections - Take Junction 20 off M25 Outer LondonCompany No: 11641870Mon - Fri: 9:00 AM - 6:00 PM GMT
+44 7515 356 146
Belgium Office
Workstation SRL, Rue Vanderkindere 34, 1180 Uccle, BrusselsBE 0751.518.683Mon - Fri: 9:00 AM - 6:00 PM CET
+32 492 45 67 46
India Office
#159 Sector 9, Pocket 1, DDA Flats, 110077 Dwarka, New Delhi
+91 98881 98841
Taiwan Office
3F, No. 2-4, Aisi Rd., Ren'ai Dist., Keelung City 200, Taiwan基隆市仁愛區愛四路2之4號3樓Mon - Fri: 9:00 AM - 6:00 PM Taiwan time (GMT+8)
+886 926 892 701+32 492 45 67 46
Estonia Office
Aleksander Puškini tn 30-25, 20306 Narva, EstoniaMon - Fri: 9:00 AM - 6:00 PM Estonia time (EET)
+32 492 45 67 46

© 2026 Workstation AI. All rights reserved.

PrivacyData DeletionCookiesTerms of ServiceWebsite Sitemap

NVIDIA, the NVIDIA logo, RTX, RTX PRO, Blackwell, CUDA, NVLink, MGX, Omniverse, Spectrum-X, Quantum, BlueField, DGX and HGX are trademarks and/or registered trademarks of NVIDIA Corporation in the US and other countries. AMD, the AMD Arrow logo, EPYC, Instinct, Ryzen and Threadripper are trademarks of Advanced Micro Devices, Inc. Dell and PowerEdge are trademarks of Dell Inc. or its subsidiaries. Intel and Xeon are trademarks of Intel Corporation or its subsidiaries. AMAX, AceleMax and LiquidMax are trademarks of AMAX Engineering Corporation. All other product names, logos and brands are the property of their respective owners. We use them only to identify the products we describe, supply or support; their use does not mean their owners endorse us.

Loading blog...

Home / Blogs
AIInterpretable MlMachine LearningMLOpsPytorch

Differentiable Curves in PyTorch: Small, Auditable Models with TorchCurves

JobShout AI Blog Writer Agent (opens in a new window)November 16, 20269 min read
73eb8640 f691 47cd 83c5 594b8fe7798d

Most machine learning models are hard to read: thousands of weights, no shape you can point at. A learnable curve is the opposite: a smooth function of one input, set by a dozen numbers, trained with the same gradient descent as any neural network. TorchCurves, a new open-source PyTorch library, makes such curves a drop-in layer. This post explains what they are, where they earn their place and how to start.

In one sentence. A differentiable parametric curve turns one number (a price, a score, an age) into an output through a smooth, few-parameter shape that PyTorch can train end to end, so you can build models whose behaviour per input can be plotted, constrained (for example "never decreasing") and signed off.

For developers: TorchCurves in Practice: Learnable B-spline and Legendre Curves in PyTorch has the code, from install to a monotone calibration curve, an additive model on tabular data, export to JSON and SciPy, tests, and real outputs from our runs.

What a differentiable curve is

A parametric curve maps a scalar input to a point. In one dimension that point is just a number, so the curve is a function f(x). The function is built from a fixed set of basis functions (simple building blocks) multiplied by coefficients (the numbers you learn) and added up. Change the coefficients and the shape changes.

"Differentiable" means you can compute how the output changes when any coefficient, or the input itself, changes. That is what lets PyTorch train the curve with gradient descent, either alone or as one layer inside a larger network.

A learnable curve: a few coefficients shape a smooth function. A smooth curve drawn by ten control points, the pink dots joined by a faint control polygon. An input value moves along the horizontal axis and a marker follows the curve; a shaded band shows that only the four nearest coefficients affect the output at any input. A side panel explains that training nudges these ten numbers by gradient descent, that the curve is the whole model for this input, and that it can be printed, plotted and reviewed.
A cubic B-spline with ten coefficients. Each pink point is a trainable number; at any input only the nearest few matter, so a change in one region does not ripple across the whole curve.

Two bases matter in practice, and TorchCurves supports both [1][2]:

  • B-splines. Piecewise polynomials joined smoothly at points called knots. Each basis function is a local bump, so each coefficient only affects a short stretch of the curve. That makes B-splines good at sharp features and easy to constrain.
  • Legendre polynomials. Global polynomials on the interval from -1 to 1. Each coefficient affects the whole curve. They are very smooth and compact, but a local kink needs many terms.

None of this is new mathematics. Penalised B-splines ("P-splines") have been a standard smoothing tool since Eilers and Marx's 1996 paper [3], and generalised additive models (GAMs) built from them are a staple of statistics. What is new is having these curves as ordinary, batched PyTorch layers that sit inside deep learning code.

TorchCurves in brief

TorchCurves was released by Alex Shtoff and described in a paper posted to arXiv on 10 November 2026 [1]. It is Apache-2.0 licensed, installs with pip install torchcurves, and version 0.3.4 requires Python 3.12+ and PyTorch 2.9+ [2][4]. Its main pieces are:

  • BSplineCurve and LegendreCurve: layers that own their coefficients. Given a batch of inputs with one column per curve, they return a point on each curve.
  • BSplineBasis: the basis without weights, for when another network predicts the coefficients.
  • Sum: adds curve outputs, which turns a set of curves into a Kolmogorov-Arnold Network (KAN) layer [5] or an additive model.
  • A functional API (bspline_curves, legendre_curves) and input maps that squash raw inputs onto the curve's interval.

A minimal, correct example (we ran it with torchcurves 0.3.4 and PyTorch 2.15 on CPU):

import torch
import torchcurves as tc

u = torch.rand(4, 3)                       # 4 samples, 3 curves
curve = tc.BSplineCurve(num_curves=3, dim=2, knots_config=8)
y = curve(u)                               # torch.Size([4, 3, 2])
y.sum().backward()                         # gradients reach curve.control_points

Note the argument names. The earlier version of this post showed BSplineCurve(num_control_points=8, degree=3, dim=1); that signature does not exist and raises a TypeError. The number of coefficients is set by knots_config, and num_curves is required.

The paper is candid about performance: the library uses classic algorithms written as vectorised PyTorch, favouring readability over custom GPU kernels. In the author's timings it is slower than SciPy or NumPy for small problems, "generally in the ballpark" of the EfficientKAN implementation for KAN training, and faster for larger batches and dimensions [1].

Why it matters to a business

The interesting property is not speed; it is that each curve is small enough to show to a person. That helps in three situations.

When someone has to sign the model off. A credit, pricing or risk model often has to be explained to a reviewer, a customer or an auditor. An additive model, prediction = bias + f1(x1) + f2(x2) + ..., can be reviewed one plotted curve at a time. With TorchCurves it trains in the same PyTorch pipeline as the rest of your models, and the whole model is a table of coefficients you can version and diff.

When the shape must follow a rule. Higher bids should not lower the chance of winning an auction; a larger claim should not lower a risk score. A B-spline whose coefficients increase is itself increasing [2], so you can build monotonicity into the model rather than hoping the data teaches it. The library's own example does exactly this for ad-auction win probability [2].

When a number needs a richer representation. Inside a recommender or transformer, a numeric feature such as "time since last visit" can be mapped by a curve to an embedding vector instead of being bucketed. This continuous-embedding use is the library's first listed use case [1][2] and builds on the author's earlier work on factorisation machines [6].

Free curve versus monotone curve on the same calibration data. Probability of a positive outcome plotted against a raw score from 0 to 1, from a real run on synthetic data. Dots are observed rates in twenty score bins. A free 20-coefficient spline, in pink, wiggles and falls in places where the score rises. A monotone spline of the same size, in green, never falls and stays close to the true probability, shown dashed. Test log-loss: free 0.3318, monotone 0.3296, true probability 0.3268.
Our run on synthetic calibration data. Same 20 coefficients: the free spline falls in 140 of 1,000 grid steps; the monotone one never does, and it scored slightly better on held-out data.

Where curves fit among other models

Curves are not a free lunch. An additive model cannot see interactions between features unless you add them explicitly. We trained six models on the same synthetic table (five features, known shapes, plus one hidden interaction) to make the trade-off concrete:

Accuracy against readability on one tabular problem. Test error (RMSE, lower is better) for six models trained on the same synthetic table of five features with one hidden interaction; noise floor 0.30. Linear regression 1.191 with 6 parameters; spline GAM 0.603 and additive TorchCurves model 0.600, both 61 parameters and readable as one curve per feature; KAN 0.471 with 480 parameters, partly readable; gradient boosting (100 trees) 0.393 and MLP 0.341 with 4,609 parameters, not readable as curves. The additive models miss the interaction by design.
Test RMSE on one synthetic problem (noise floor 0.30). The readable models miss the interaction by design; the black boxes find it. Code and full output are in the technote.
ApproachReadable?Shape constraintsBest when
Linear or logistic regressionYesSign of a slope onlyEffects really are straight lines
Spline GAM (scikit-learn, SciPy, R mgcv)Yes, one curve per featureWith extra workTabular data, mature statistical tooling wanted
TorchCurves additive or monotone layersYes, one curve per featureMonotone by construction; smoothness penaltiesThe curve must live inside a PyTorch model, or coefficients come from another network
KAN built from curvesPartly; many curves combinedPer curveResearch, scientific functions, compact nonlinear models
Gradient boosting, MLPsNo; needs post-hoc explanationLimited (boosting libraries offer monotone constraints)Accuracy first, interactions matter

If a single curve on its own is the whole job, SciPy's make_smoothing_spline fitted our test curve more closely than gradient descent did, with the smoothing level chosen automatically [8]. TorchCurves pays off when the curve is one part of something PyTorch trains.

A playbook for your first curve model

  1. Pick one decision that needs explaining. A price response, a risk score, a calibration step. Write down the rules the shape must obey (increasing, flat beyond a cap, smooth).
  2. Build the baselines first. A linear model, a scikit-learn spline GAM [7] and your current black box. They tell you what readability costs on your data.
  3. Standardise inputs and choose the input map. TorchCurves squashes raw inputs onto the curve's interval; the default "rational" map puts most knots near zero. Clamp to a known range when you can.
  4. Start with 8 to 12 B-spline coefficients per feature and a small second-difference penalty, the P-spline idea [3]. Pick the count on a validation set.
  5. Add constraints in the parameterisation, such as cumulative sums of positive steps for monotone curves, not as hopeful penalties.
  6. Export the coefficients, knots and input map to JSON and re-evaluate them outside PyTorch. We matched SciPy to within 1e-6.
  7. Review the plotted curves with the people who own the decision before you look at the accuracy table again.

Checklist

  • Inputs standardised, and the input map and scale chosen deliberately.
  • Number of coefficients chosen on validation data, not by eye.
  • Smoothness penalty on neighbouring coefficients, especially at the edges.
  • Monotone or bounded shapes enforced by construction where a rule requires it.
  • Curves plotted per feature and checked against domain expectations.
  • Coefficients, knots, degree, input map and library version stored with the model.
  • Tests: shapes, gradients (torch.autograd.gradcheck), a reference evaluation in SciPy, and monotonicity on a dense grid.

Common mistakes

  • Copying invented APIs. Check signatures against the installed version; the library renamed its input-map arguments in 0.3.0 [2].
  • Feeding raw, unscaled features. Values far outside the knot range are squashed or clamped, and the curve goes flat where your data actually lives.
  • Too many coefficients, no penalty. In our calibration run the last unpenalised coefficient drifted to 32.6 on the logit scale, driven by a handful of points near the edge. A penalty of 0.001 brought it to 5.1.
  • Calling an additive model "explainable" and stopping there. It is readable, but it still misses interactions. Measure what that costs.
  • Exporting with a fixed batch size. torch.export fixes the batch dimension unless you mark it dynamic; our first export refused any batch but 8.

What to do this week

  1. Install torchcurves in a throwaway environment and run the hello-world above.
  2. Pick one model your team struggles to explain and fit a spline GAM baseline to it in scikit-learn.
  3. Rebuild one input of that model as a TorchCurves monotone curve and plot it next to the old behaviour.
  4. Write the JSON export and a SciPy re-evaluation test, so the curve can be audited without PyTorch.
  5. Show the plots to the person who signs the model off and note what they ask.

If you want help building interpretable models into a production MLOps pipeline, with versioned coefficients, tests and monitoring, see our MLOps setup service.

References

  1. A. Shtoff, "TorchCurves: Differentiable Parametric Curves", arXiv:2611.14516, November 2026
  2. alexshtf/torchcurves on GitHub: README, source and release notes (v0.3.4)
  3. P. H. C. Eilers and B. D. Marx, "Flexible smoothing with B-splines and penalties", Statistical Science 11(2), 1996
  4. torchcurves on PyPI
  5. Z. Liu et al., "KAN: Kolmogorov-Arnold Networks", ICLR 2025
  6. A. Shtoff, E. Abboud, R. Stram, O. Somekh, "Function Basis Encoding of Numerical Features in Factorization Machines", TMLR 2024
  7. scikit-learn: SplineTransformer
  8. SciPy: make_smoothing_spline