What is an AI tensor?
In deep learning a tensor is a multidimensional array holding numbers on a regular grid with a variable number of axes; model weights, inputs, activations and gradients are stored and processed as tensors.
Unlike scalars, vectors and matrices, with zero, one and two axes respectively, a tensor generalises them and can have more than two. The mathematical notion of a tensor is broader; in deep learning the term mostly means a multidimensional array.
- Topic
- Infrastructure and runtime
- Also known as
- Multidimensional array
How an AI tensor works
- A tensor's shape gives the element count on each axis, for example batch, sequence length and hidden size.
- Its data type, such as BF16 or INT8, sets how many bits each element takes.
- Layers apply matrix multiplications and element-wise operations to tensors.
- Large tensors can be split across GPUs and processed with tensor parallelism.
In more detail
Device placement, memory layout and autograd metadata
Beyond shape and data type, every runtime tensor has a device placement (CPU versus GPU), a memory layout (row-major/contiguous versus strided) and, during training, automatic differentiation metadata (`requires_grad` and gradient buffers). Strided or non-contiguous tensors allow zero-copy slicing and transposing, though many GPU kernels require contiguous memory before execution.
Current low-precision data types
While BF16 (2 bytes) and INT8 (1 byte) remain common, current inference and training pipelines increasingly rely on FP8 (E4M3/E5M2) and 4-bit formats such as INT4, NF4 or hardware-supported FP4/MXFP4 to cut VRAM footprint and memory-bandwidth bottlenecks. Lower-precision weight tensors are paired with higher-precision scaling factors (group-wise scales) to preserve numerical accuracy.
Memory consumers beyond weight tensors
Estimating GPU memory from weight tensors alone underestimates real runtime needs. Inference also allocates large dynamic tensors for the KV cache, which grows linearly with batch size and context length, plus workspace activations, while training adds gradients and optimiser states that often exceed weight memory severalfold.
Commonly confused terms
| Term | How it differs |
|---|---|
| Embedding | An embedding is a learned dense vector (typically a 1D tensor per item or 2D tensor for a batch/vocabulary) representing semantic meaning, whereas a tensor is the underlying general data container used for embeddings, weights, KV caches and activations alike. |
Why an AI tensor matters for on-premises AI
The linear algebra chapter of a deep learning textbook defines a tensor as an array of numbers arranged on a regular grid with a variable number of axes, used when more than two axes are needed. A paper proposing intra-layer model parallelism for language models splits transformer weight tensors across GPUs to train models too large for one GPU's memory. Example calculation: a BF16 weight tensor of shape 4096×4096 holds about 16.8 million elements and takes about 33.6 MB.
Before bringing a new model onto in-house servers, an AI platform team lists the shapes and data types of its weight tensors to compute total GPU memory needs and decide how many GPUs are required.
Common questions
How does a tensor differ from a matrix?
A matrix is a two-axis tensor. A tensor can have more axes; a batch of images, for example, is a four-axis tensor.
Why does a tensor's shape matter?
It sets compatibility between operations and memory needs. Mismatched shapes cause errors; larger shapes need more memory and compute.
Related terms
Sources
- Deep Learning, Chapter 2: Linear Algebra, 2016
- Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism, 2019
In the glossary: Glossary, R to Z