Skip to content

deepbox

Upgrading from 1.0

Deepbox 1.5 is backward compatible with 1.0. No export was removed or renamed. This page lists the places where results or types changed.

Short version

Your 1.0 code still compiles and runs. Check the dtype rules, any tests that pin exact random values, and TypeScript code that annotates the result of forward as Tensor.

Dtype rules

Float operations keep the input float dtype. A float32 tensor stays float32 through exp, sqrt, sum, mean, activations and the rest, where 1.0 returned float64 for several of them. Integer input to an operation with a fractional result (mean, div, exp, softmax and similar) gives float32. Integer reductions keep the integer dtype. Index results (argsort, argmax, digitize, searchsorted, nonzero) are int32.

Call t.astype("float64") when you need double precision.

Mixed dtypes promote

Binary operations on tensors of different dtypes now promote the way PyTorch does, instead of throwing DTypeError. A JavaScript number never changes a tensor's dtype.

promotion.ts
import { promoteTypes } from "deepbox/core";import { tensor } from "deepbox/ndarray"; const ints = tensor([1, 2, 3], { dtype: "int32" });const floats = tensor([0.5, 0.5, 0.5], { dtype: "float32" }); console.log(ints.add(floats).dtype); // float32console.log(promoteTypes("float32", "float64")); // float64

Training on plain tensors

Data no longer has to be wrapped in parameter(). When gradient tracking is on and the module has trainable parameters, module.forward(tensor) returns a GradTensor that tracks the weights. Inside noGrad() it returns a plain Tensor. Optimizers skip parameters that have no gradient, as PyTorch does. In 1.0 they threw NotFittedError.

Layers without trainable parameters, such as pooling, dropout, activations and normalization without affine parameters, return a plain Tensor for plain input. Read the result directly instead of going through .tensor.

In TypeScript, layer.forward(tensor) is now typed AnyTensor, which is Tensor | GradTensor. Code that annotated the result as Tensor should use AnyTensor. Custom modules can declare a single forward(x: AnyTensor): AnyTensor.

Names

Every public name is now camelCase, for example matrixPower, toDatetime, ttestInd, crossValScore, multivariateNormal and checkXY. The snake_case names from 1.0 keep working and are marked @deprecated in the type declarations. The same holds for methods and options, and when both spellings of an option are given the camelCase one wins.

Seeded randomness

Several modules replaced weak private generators with the library's seeded generator: trees and forests, bagging, k-means, splitters, QuantileTransformer and DataFrame.sample. The same seed still gives the same result from run to run, but not the same result as 1.0. Layer weight initialization also matches PyTorch now, so seeded models start from different weights. Tests that pin exact random values need new expected values.

Stricter input checks

Many functions now throw a typed error where 1.0 returned silent garbage: NaN or infinite input to estimators, invalid buffers in readParquet and readXlsx, a truncated CIFAR-10 download, string or complex input to numeric code, and invalid parameters. A few error classes changed to a more precise one. For example, solveBanded throws InvalidParameterError for an invalid band width.

Smaller changes

  • SpectralNorm registers the wrapped module as the child module, so state dicts saved from 1.0 models that contain SpectralNorm do not load.
  • mannwhitneyu and wilcoxon use exact p-values for small samples and the mannwhitneyu statistic is U1, following current SciPy.
  • Layers compute in their parameter dtype and cast the input, as Linear already did, so recurrent layers accept integer input.
  • parameter(...) keeps requiresGrad: true when you create it inside noGrad(). Only the operations run inside noGrad() skip recording.

Results that were wrong in 1.0

About 1,500 fixes landed in 1.5.0, and some change numbers you may have stored in tests. Run your numerical tests again before you trust old expected values. The most visible ones:

  • Trainer passed plain tensors to the model, so layers returned untracked results and real models did not train. It now trains.
  • OneClassSVM flagged 88 percent of the training rows as outliers with nu = 0.1. It now flags about 10 percent, as scikit-learn does.
  • mannwhitneyu, wilcoxon, kstest, ks2samp and anderson now match SciPy 1.17, including exact p-values for small samples.
  • cumsum and cumprod without an axis returned the wrong shape, floorDiv and mod disagreed with NumPy for large or fractional values, and int32 multiplication lost low bits.
  • Non-symmetric eig now uses a real double-shift QR algorithm.
  • fetch20Newsgroups and fetchIMDB used default URLs that returned 404. They now load the official archives.
  • Plot tick labels (2.5 was drawn as 3), PNG grids and text, and twinx axes were corrected.

The complete list of fixes and additions is in the changelog.