Skip to content
TensaCoPublic

About

No description, website, or topics provided.

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

TensorCode

Website: tensorcode.dev · Docs: tensorcode.dev/docs · Python: tensacode-py · TypeScript: tensacode-ts · Packages: PyPI · npm

TensorCode is an SDK for programs that carry both the logic you can write down and the parameters you have to learn. Write a bounded numerical function. TensorCode compiles it to a circuit that runs exactly, checks out against every declared input, trains only the numbers you mark as trainable, executes as a NumPy program, a PyTorch graph or an attention machine, and saves as a few kilobytes of JSON that load in Python, TypeScript and the browser without evaluating code.

The newest piece turns that into a cost story. A large model costs the same on every request, forever. The Python distillation loop has an authoring model write a small program for a workload you already run through that large model, compiles the reply without executing it, scores it on cases the author never saw, serves it on a CPU in microseconds, escalates the inputs it does not claim, and repairs it from those escalations. The large model runs at authoring time and leaves the request path.

Status: 0.4.0 alpha. APIs may change between alphas. The published checkpoints are small experiments; the measured behavior and its limits are in validation. The distillation loop and weight patches are in the Python source checkout, not yet in a published release, and their measured example uses recorded author replies rather than a live model.

What TensorCode unlocks

  • Rules you verify instead of prompt for. Compile a bounded function over declared integer ranges and check it on every input: 256 cases for one int32(min=-128, max=127), no sampling, no model call. The artifact alone reproduces the rule; nothing is fitted.
  • Learned numbers inside readable structure. Mark the thresholds and weights you want learned. Gradient descent moves those and only those. The branches and arithmetic around them stay as written, and a trained algorithm exports to standalone NumPy source you can read.
  • One algorithm, three executors. The same artifact runs as a NumPy reference program, a native PyTorch autograd graph and a scheduled attention machine. compare checks any two case by case, and a hard attention machine converts back to the symbolic program. The algorithm's structure can also be projected into a pretrained transformer's attention as a structural prior.
  • Distilled programs that serve in microseconds from kilobytes. The recorded ticket-routing example yields a 1,770-byte artifact that runs in about 45 microseconds per call on the reference executor, gives zero wrong answers on the hidden cases it claims, and sends 30% of fresh traffic to the fallback. Agreement is measured against the teacher you supply, never assumed.
  • Weight edits as patches you can review. Render tensors as text a model can read, parse the edit statements it writes back with a fixed grammar, and store the change as a hash-pinned JSON patch in sparse, dense, low-rank or projection form. A patch applies to any state dictionary and refuses a base that has drifted.
  • Tools that own their models and remember where feedback came from. Investigator, Planner, Chatbot, Decision and Scene train on reviewed feedback with explicit provenance and save as data-only artifacts that reload from disk, from the Hugging Face Hub, or in the other language.
  • Artifacts are data, never code. JSON configuration and safetensors weights, no pickles. Loading never evaluates source. The same files load in Python and TypeScript, and compiled programs also run in the browser on WebAssembly or WebGPU.

Guides: compiled programs, algorithm substrates, distilled programs and weight patches, validation.

This is the umbrella repository. Each language implementation is its own repository, included here as a git submodule under tensacode/. This repository also holds the product site for tensorcode.dev.

Implementations

Language Directory Package Status
Python tensacode/python tensorcode (pip) Implemented. The reference implementation
TypeScript tensacode/typescript tensorcode (npm) Implemented. A port that matches Python and shares its file formats (parity)
C++ tensacode/cpp Not yet implemented
C# tensacode/csharp Not yet implemented
Dart tensacode/dart Not yet implemented
Java tensacode/java Not yet implemented
Kotlin tensacode/kotlin Not yet implemented
Swift tensacode/swift Not yet implemented

Install

Python 3.11 or newer:

python -m pip install 'tensorcode[tools]'

The core package (pip install tensorcode) has no dependencies; the tools extra adds PyTorch and Transformers for the owned models used below.

Node.js 20.16 or newer:

npm install tensorcode

The install guide lists the Python extras and how to set up each repository for development.

Deterministic and learned computation

The Python program guide and the TypeScript program guide cover the scalar compiler: supported syntax, exact/relaxed/hybrid gradient policies, state, verification and shared artifacts. Python provides reference execution and a PyTorch bridge; TypeScript adds WASM and restricted float32 WebGPU execution. These are bounded numerical programs, not compilation of arbitrary applications or host effects.

The algorithm framework runs typed tensor algorithms on symbolic (ALG.0), native differentiable (ALG.1) and scheduled attention (ALG.2) executors, with structural priors for pretrained attention and sensor-driven G1 control. The distillation guide builds the author, verify, serve, route and repair loop on top of it. Each target states its execution or approximation contract explicitly.

The robotics lab is the shared interface for annotating and diagnosing recorded G1 walking and manipulation, with sensor traces, controller architecture and measured session evidence. Its full handling demonstration walks to a camera-localized workcell, grasps and transports a payload, then uses tactile support transfer to place and release it. Recorded comparisons measure the effect of online payload-load compensation. Shared warehouse sessions add language-conditioned parallel/sequential workcells, observed scene and task trees, and grounded question previews. Native Ψ₀, Ψ₀.1 and GR00T policy recordings, plus π₀ on ALOHA arms, are separate references with their own task contracts and retained failures.

A first program

This trains an Investigator to rank two supplied hypotheses from log evidence, then saves and reloads it. It runs offline on a CPU in seconds.

import torch
from tensorcode import training
from tensorcode.tools.investigator import Investigator

torch.manual_seed(0)
model = Investigator({"vocabulary": ["database", "network", "connection", "refused", "packet", "loss"],
                      "dimensions": 16, "slots": 2, "steps": 1})
trainer = training.Trainer.from_tool(model, optimizer=torch.optim.AdamW(model.parameters(), lr=0.01))

hypotheses = [{"id": "database", "text": "database connection refused"},
              {"id": "network", "text": "network packet loss"}]

def case(log_line):
    return {"question": "which component failed",
            "evidence": [{"source_id": "log:1", "text": log_line}],
            "hypotheses": hypotheses}

# Reviewed feedback, with explicit provenance, becomes training experience.
experiences = [trainer.capture(case("connection refused"), "database", source="review:1"),
               trainer.capture(case("packet loss"), "network", source="review:2")]
losses = trainer.fit(experiences, epochs=30)

model.save_pretrained("./investigator")
restored = Investigator.from_pretrained("./investigator")
print(restored(case("packet loss"))["selected_id"])  # network

Two authored cases show the lifecycle; they do not show that the model can investigate anything. The same program in TypeScript is in the TypeScript README, and the architecture overview explains operations, tools, tracing, training and artifacts.

Repository layout

Path Contents
tensacode/<language>/ Language implementations, one git submodule each
site/ The tensorcode.dev site: static pages, styles and images (site/README.md)
scripts/site/build-docs.mjs Generates site/docs/ from the implementations' READMEs and guides, plus the shared pages in scripts/site/pages/
scripts/site/check-links.mjs Checks every internal link, anchor and code block of the built site
wrangler.jsonc, scripts/site/worker.js The Cloudflare Worker that serves site/ at tensorcode.dev
.github/workflows/ site.yml builds and checks the site; deploy.yml publishes it

Clone with the implemented submodules (the other language repositories are private placeholders for now):

git clone https://github.com/TensaCo/tensacode
cd tensacode
git submodule update --init tensacode/python tensacode/typescript

Site development

The scripts need only Node.js 20 or newer; there is nothing to install.

node scripts/site/build-docs.mjs      # writes site/docs/ (git-ignored)
node scripts/site/check-links.mjs     # internal links, anchors and code blocks
npx wrangler dev                      # preview at http://localhost:8787

Every push and pull request runs the build and the link check (site.yml). Every push to develop also deploys to tensorcode.dev (deploy.yml). The deploy needs two repository secrets, which the owner adds under Settings > Secrets and variables > Actions:

Secret Value
CLOUDFLARE_API_TOKEN A Cloudflare API token with Workers edit permission for the account and the tensorcode.dev zone (the "Edit Cloudflare Workers" template)
CLOUDFLARE_ACCOUNT_ID The ID of the Cloudflare account that owns tensorcode.dev

To deploy by hand: node scripts/site/build-docs.mjs && npx wrangler deploy.

Credentials live in git-ignored env files at the repository root, one per environment. Each has a committed template: copy .env.<name>.example to .env.<name> and fill it in.

File Used for
.env.local Local development (npx wrangler dev, site scripts); optional with npx wrangler login
.env.prod Deploying to production from your machine (set -a; . ./.env.prod; set +a)
.env.gh The GitHub Actions secrets above; upload with gh secret set -f .env.gh -R TensaCo/tensacode

There is no separate dev or staging environment, so there is no .env.dev.

Contributing

Library changes belong in tensacode-py and tensacode-ts; site changes belong here. See CONTRIBUTING.md.

License

MIT. Each implementation carries its own license file.

About

No description, website, or topics provided.

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages