lmtorch

lmtorch is a CPU tensor host for LMScript: tensor operations, automatic differentiation, model layers, optimizers, and safetensors and CSV input and output through one released native executable (version 0.5.1). This page is the quick reference; details are in the linked pages.
Install and run
npm install -g @lmctl-ai/lmctl
lmctl init
lmctl autorun https://lmctl.com/tools/lmtorch/lmtorch_solo.lms
A block that declares cli="lmtorch" and install="github:lmctl-ai/lmtorch@latest" downloads the release binary when lmtorch is not on PATH; pin a tag such as @v0.5.1 for reproducible runs.
Host protocol
| Command | Effect |
|---|---|
| lmtorch --version | Prints lmtorch and the version number, exit 0. |
| lmtorch --lmcode-schema | Prints a readable summary of the host API grouped by type. |
| lmtorch --lmcode-schema --json | Prints the exact embedded host schema bytes (schema 2, name lmtorch) that lmscript compiles against. |
| lmtorch --lmcode-signatures | Prints one canonical signature per line (context, function and method entries). |
| lmtorch --lmcode FILE.dslb | Runs compiled bytecode under the v1 invocation manifest and prints one terminal return frame. Several files may follow one --lmcode. |
| --first FILE.dslb, --last FILE.dslb | Additional bytecode files ordered before or after the --lmcode files in the same invocation. |
Exit codes: 0 success, 2 command-line or manifest error, 3 load or run error, 4 application or output error. Retired flag spellings are rejected.
Context objects and types
| Name | Kind | Role |
|---|---|---|
| torch | context object of type Torch | Tensor constructors, seeding, thread count, grad mode, loading of tensors, bundles, models and CSV, handle marks. |
| out | context object of type Out | Builds the Json result of the block with set and verifies expectations with check. |
| Tensor | type, 88 methods | CPU tensor: shape, indexing, arithmetic, reductions, activations, autograd, save and CSV output. Operators + - * and unary minus map to add, sub, mul and neg; division is the div method. |
| TensorList | type, 3 methods | Ordered list of tensors. |
| Bundle | type, 7 methods | Named tensors, stored as one safetensors file. |
| Model | type, 24 methods | Sequential model built by chaining layer methods. |
| Optimizer | type, 4 methods | Optimizer created from a model. |
| DType | enum | F32, F64, I64, BOOL. |
Most used calls
| Task | Calls |
|---|---|
| Create tensors | torch.tensor(json text), torch.zeros, torch.ones, torch.full, torch.rand, torch.randn, torch.randint (shapes are 1 to 4 int arguments) |
| Reproducibility | torch.manual_seed(int), torch.set_num_threads(int) |
| Read values | Tensor.item, Tensor.shape, Tensor.sum, Tensor.mean |
| Gradients | Tensor.requires_grad(true), Tensor.backward, Tensor.grad, Tensor.zero_grad, torch.grad_enabled(bool) |
| Files | Tensor.save, torch.load, torch.load_model, Model.save; paths stay inside the working directory |
| Result | out.set(key, value) chained, out.check(condition, message) |
| Memory in long loops | torch.mark and torch.release |
Minimal example
A complete lmscript file, taken from examples/tensor-sum-dsl.lms in the repository. run_lmcode compiles the block, runs the host and returns an object with ok and result.
p = _lmcode_ cli="lmtorch" install="github:lmctl-ai/lmtorch@latest";
let values = torch.tensor("[[1.0, 2.0], [3.0, 4.0]]");
let total = values.sum().item();
out.check(total == 10.0, "sum must be 10");
out.set("shape", values.shape()).set("sum", total);
end _lmcode_
run = run_lmcode(p);
if (!run.ok) { println(f"lmtorch {run.phase} error {run.code}: {run.message}"); exit(1); }
result = run.result;
println(f"shape {result.shape}, sum {result.sum}");
Standard library
lmtorch 0.5.1 vendors the lmcode_std_v3 catalog of the lmcode-cpp commit pinned in sdk.lock: 206 canonical signatures (83 functions and 123 methods on 16 standard types). The current lmcode_std_v3 catalog has 226 signatures, adding the REST and CLI interfaces; lmtorch picks those up when it syncs its SDK pin and releases.
More
- Skill: task-oriented instructions for agents.
- Guide: concepts, autograd, models and files.
- Reference: every host method, flag, exit code and std signature.
- Get started: checked quickruns.
- Examples book with runnable source.
- Source repository and releases.