TensorCode Docs

DocsInstall

Install#

TensorCode has two implementations with the same contracts: the Python package tensorcode (the reference) and its TypeScript port. Artifacts, experience files and session files move between them, so you can train in one language and serve in the other.

PythonTypeScript
Packagetensorcode 0.4.0a3tensorcode 0.4.0-alpha.3
RuntimePython 3.11 or newerNode.js 20.16 or newer, ESM only
NumericsPyTorch, CPU or GPUBuilt-in autograd core, CPU, no runtime dependencies
SourceTensaCo/tensacode-pyTensaCo/tensacode-ts

Python (pip)#

Python 3.11 or newer:

python -m pip install 'tensorcode[tools]'

The core package has no dependencies, and importing it loads neither PyTorch nor the network. Choose the extras for the parts you use:

ExtraAdds
toolsOwned models, training and Hugging Face loading (PyTorch, Transformers)
vecVector operations only (PyTorch, NumPy, safetensors)
localAdapter for a local multimodal Transformers model
diffusiontools plus diffusers, for image decoders
pretrainedAlias of tools
devpytest, build, Pillow and PyArrow. The full test suite also needs diffusion

Check the install:

python -c "import tensorcode; print(tensorcode.__version__)"   # 0.4.0a3

To work on the library itself, clone it and install it in editable mode:

git clone https://github.com/TensaCo/tensacode-py
cd tensacode-py
python -m pip install -e '.[tools,diffusion,dev]'
python -m pytest -q

TypeScript (npm)#

Node.js 20.16 or newer:

npm install tensorcode

The package is ESM only (import, not require) and ships its own type declarations. It has no runtime dependencies. The optional peer @huggingface/transformers is needed only for integrations.LocalModel.

Check the install:

node --input-type=module -e "import { version } from 'tensorcode'; console.log(version)"   # 0.4.0-alpha.3

To work on the library itself:

git clone https://github.com/TensaCo/tensacode-ts
cd tensacode-ts
npm install          # also builds dist/
npm test             # needs neither Python nor network access

Imports side by side#

The entry points match module for module. TypeScript uses camelCase for the API and keeps Python's snake_case for saved and reported data.

from tensorcode import trace, training
from tensorcode.ops.vec import Classify
from tensorcode.ops.vec.encode import VocabularyEncoder
from tensorcode.tools.investigator import Investigator
import { trace } from 'tensorcode';
import { Trainer, loadExperience } from 'tensorcode/training';
import { Classify, VocabularyEncoder } from 'tensorcode/ops/vec';
import { Investigator } from 'tensorcode/tools';

Next steps#