lmtorch reference

Command-line flags, exit codes, context objects, host types and methods, and standard-library signatures of lmtorch 0.5.1, generated from the repository schema (schema/lmtorch.host.json), the host source and the vendored lmcode std schema. The host schema declares 214 method signatures on 7 types. Parameter and return types are int, float, string, bool, void and the host or standard types named here.

Command line

CommandEffect
lmtorch --versionPrints lmtorch and the version number, exit 0.
lmtorch --lmcode-schemaPrints a readable summary of the host API grouped by type.
lmtorch --lmcode-schema --jsonPrints the exact embedded host schema bytes (schema 2, name lmtorch) that lmscript compiles against.
lmtorch --lmcode-signaturesPrints one canonical signature per line (context, function and method entries).
lmtorch --lmcode FILE.dslbRuns compiled bytecode under the v1 invocation manifest and prints one terminal return frame. Several files may follow one --lmcode.
--first FILE.dslb, --last FILE.dslbAdditional bytecode files ordered before or after the --lmcode files in the same invocation.

Exit codes

Exit codePhaseMeaning
0noneSuccess.
2cliUsage error (CLI_USAGE), retired or unknown flag, invalid invocation manifest, or a missing or nonboolean dry value; no host work is done.
3load or runBytecode failed verification against the embedded schema (for example LOAD_BAD_BYTECODE), or a program failed while running (host errors are reported as RUN_HOST).
4appApplication-phase failure, or the result could not be written to standard output.

Used from lmscript

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}");

Context and host types

NameKindRole
torchcontext object of type TorchTensor constructors, seeding, thread count, grad mode, loading of tensors, bundles, models and CSV, handle marks.
outcontext object of type OutBuilds the Json result of the block with set and verifies expectations with check.
Tensortype, 88 methodsCPU 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.
TensorListtype, 3 methodsOrdered list of tensors.
Bundletype, 7 methodsNamed tensors, stored as one safetensors file.
Modeltype, 24 methodsSequential model built by chaining layer methods.
Optimizertype, 4 methodsOptimizer created from a model.
DTypeenumF32, F64, I64, BOOL.

Enum DType

ValueMeaning
F3232-bit float
F6464-bit float
I6464-bit integer
BOOLboolean, one byte in safetensors

Tensor operators

Operator keyTensor method
+add
-sub
*mul
negneg
r+add
r-rsub
r*mul

Keys beginning with r apply when the tensor is the right operand. There is no operator for division; call div.

Torch methods

MethodSignatures
versionversion() -> string
manual_seedmanual_seed(int) -> void
set_num_threadsset_num_threads(int) -> void
grad_enabledgrad_enabled(bool) -> void
is_grad_enabledis_grad_enabled() -> bool
zeroszeros(int) -> Tensor; zeros(int, int) -> Tensor; zeros(int, int, int) -> Tensor; zeros(int, int, int, int) -> Tensor
onesones(int) -> Tensor; ones(int, int) -> Tensor; ones(int, int, int) -> Tensor; ones(int, int, int, int) -> Tensor
fullfull(int, float) -> Tensor; full(int, int, float) -> Tensor; full(int, int, int, float) -> Tensor; full(int, int, int, int, float) -> Tensor
randrand(int) -> Tensor; rand(int, int) -> Tensor; rand(int, int, int) -> Tensor; rand(int, int, int, int) -> Tensor
randnrandn(int) -> Tensor; randn(int, int) -> Tensor; randn(int, int, int) -> Tensor; randn(int, int, int, int) -> Tensor
randintrandint(int, int, int) -> Tensor; randint(int, int, int, int) -> Tensor
randpermrandperm(int) -> Tensor
arangearange(int) -> Tensor; arange(float, float, float) -> Tensor
linspacelinspace(float, float, int) -> Tensor
eyeeye(int) -> Tensor
scalarscalar(float) -> Tensor
tensortensor(string) -> Tensor; tensor(string, DType) -> Tensor
wherewhere(Tensor, Tensor, Tensor) -> Tensor
listlist() -> TensorList
catcat(TensorList, int) -> Tensor
stackstack(TensorList, int) -> Tensor
loadload(string) -> Tensor; load(string, string) -> Tensor
savesave(string, Tensor) -> void
bundlebundle() -> Bundle
openopen(string) -> Bundle
read_csvread_csv(string, bool) -> Tensor
sequentialsequential() -> Model
load_modelload_model(string) -> Model
sgdsgd(Model, float) -> Optimizer; sgd(Model, float, float) -> Optimizer; sgd(TensorList, float) -> Optimizer
adamadam(Model, float) -> Optimizer; adam(TensorList, float) -> Optimizer
adamwadamw(Model, float, float) -> Optimizer
markmark() -> int
releaserelease(int) -> int
live_tensorslive_tensors() -> int

Tensor methods

MethodSignatures
numelnumel() -> int
dimdim() -> int
sizesize(int) -> int
shapeshape() -> string
dtypedtype() -> DType
itemitem() -> float
item_intitem_int() -> int
valuevalue(int) -> float
value_intvalue_int(int) -> int
setset(int, float) -> self
to_textto_text() -> string
to_jsonto_json() -> string
toto(DType) -> Tensor
addadd(Tensor) -> Tensor; add(float) -> Tensor
subsub(Tensor) -> Tensor; sub(float) -> Tensor
rsubrsub(float) -> Tensor
mulmul(Tensor) -> Tensor; mul(float) -> Tensor
divdiv(Tensor) -> Tensor; div(float) -> Tensor
powpow(float) -> Tensor
negneg() -> Tensor
matmulmatmul(Tensor) -> Tensor
maximummaximum(Tensor) -> Tensor
minimumminimum(Tensor) -> Tensor
absabs() -> Tensor
expexp() -> Tensor
loglog() -> Tensor
sqrtsqrt() -> Tensor
squaresquare() -> Tensor
sinsin() -> Tensor
coscos() -> Tensor
signsign() -> Tensor
floorfloor() -> Tensor
roundround() -> Tensor
clampclamp(float, float) -> Tensor
relurelu() -> Tensor
sigmoidsigmoid() -> Tensor
tanhtanh() -> Tensor
gelugelu() -> Tensor
leaky_reluleaky_relu(float) -> Tensor
softmaxsoftmax(int) -> Tensor
log_softmaxlog_softmax(int) -> Tensor
gtgt(Tensor) -> Tensor; gt(float) -> Tensor
ltlt(Tensor) -> Tensor; lt(float) -> Tensor
gege(float) -> Tensor
lele(float) -> Tensor
eqeq(Tensor) -> Tensor; eq(float) -> Tensor
sumsum() -> Tensor; sum(int) -> Tensor; sum(int, bool) -> Tensor
meanmean() -> Tensor; mean(int) -> Tensor; mean(int, bool) -> Tensor
stdstd() -> Tensor; std(int, bool) -> Tensor
varvar() -> Tensor
normnorm() -> Tensor
maxmax() -> Tensor
minmin() -> Tensor
amaxamax(int) -> Tensor
aminamin(int) -> Tensor
argmaxargmax() -> Tensor; argmax(int) -> Tensor
argminargmin(int) -> Tensor
reshapereshape(int) -> Tensor; reshape(int, int) -> Tensor; reshape(int, int, int) -> Tensor; reshape(int, int, int, int) -> Tensor
flattenflatten() -> Tensor
tt() -> Tensor
transposetranspose(int, int) -> Tensor
unsqueezeunsqueeze(int) -> Tensor
squeezesqueeze() -> Tensor; squeeze(int) -> Tensor
sliceslice(int, int, int) -> Tensor
selectselect(int, int) -> Tensor
index_selectindex_select(int, Tensor) -> Tensor
linearlinear(Tensor) -> Tensor; linear(Tensor, Tensor) -> Tensor
mse_lossmse_loss(Tensor) -> Tensor
l1_lossl1_loss(Tensor) -> Tensor
smooth_l1_losssmooth_l1_loss(Tensor) -> Tensor
cross_entropycross_entropy(Tensor) -> Tensor
nll_lossnll_loss(Tensor) -> Tensor
bce_with_logitsbce_with_logits(Tensor) -> Tensor
allcloseallclose(Tensor, float, float) -> bool
equalequal(Tensor) -> bool
is_finiteis_finite() -> bool
anyany() -> bool
allall() -> bool
requires_gradrequires_grad() -> bool; requires_grad(bool) -> self
backwardbackward() -> void
gradgrad() -> Tensor
has_gradhas_grad() -> bool
zero_gradzero_grad() -> self
detachdetach() -> Tensor
cloneclone() -> Tensor
keepkeep() -> self
savesave(string) -> self
write_csvwrite_csv(string) -> self

TensorList methods

MethodSignatures
addadd(Tensor) -> self
lenlen() -> int
atat(int) -> Tensor

Bundle methods

MethodSignatures
putput(string, Tensor) -> self
getget(string) -> Tensor
hashas(string) -> bool
keyskeys() -> StrList
metameta(string) -> string; meta(string, string) -> self
has_metahas_meta(string) -> bool
savesave(string) -> void

Model methods

MethodSignatures
linearlinear(int, int) -> self
conv2dconv2d(int, int, int) -> self; conv2d(int, int, int, int, int) -> self
max_pool2dmax_pool2d(int) -> self
flattenflatten() -> self
relurelu() -> self
tanhtanh() -> self
sigmoidsigmoid() -> self
gelugelu() -> self
leaky_reluleaky_relu(float) -> self
softmaxsoftmax(int) -> self
log_softmaxlog_softmax(int) -> self
dropoutdropout(float) -> self
layer_normlayer_norm(int) -> self
forwardforward(Tensor) -> Tensor
parametersparameters() -> TensorList
paramparam(string) -> Tensor
num_parametersnum_parameters() -> int
layerslayers() -> int
summarysummary() -> string
traintrain() -> self
evaleval() -> self
zero_gradzero_grad() -> self
savesave(string) -> void
loadload(string) -> self

Optimizer methods

MethodSignatures
zero_gradzero_grad() -> void
stepstep() -> void
lrlr() -> float
set_lrset_lr(float) -> self

Out methods

MethodSignatures
setset(string, float) -> self; set(string, int) -> self; set(string, string) -> self; set(string, bool) -> self; set(string, Tensor) -> self
appendappend(string, float) -> self; append(string, int) -> self
loglog(string) -> void
checkcheck(bool, string) -> void
failfail(string) -> void
write_textwrite_text(string, string) -> void

Standard library in lmtorch 0.5.1

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. lmtorch implements none of it; the embedded VM registers it. Std file functions are not confined to the working directory.

Functions: file (5 signatures)

FunctionSignatures
file_appendfile_append(string, string) -> void
file_existsfile_exists(string) -> bool
file_linesfile_lines(string) -> StrList
file_readfile_read(string) -> string
file_writefile_write(string, string) -> void

Functions: float (5 signatures)

FunctionSignatures
float_listfloat_list() -> FloatList
float_mapfloat_map() -> FloatMap
float_pqfloat_pq() -> FloatPQ
float_queuefloat_queue() -> FloatQueue
float_stackfloat_stack() -> FloatStack

Functions: int (5 signatures)

FunctionSignatures
int_listint_list() -> IntList
int_mapint_map() -> IntMap
int_pqint_pq() -> IntPQ
int_queueint_queue() -> IntQueue
int_stackint_stack() -> IntStack

Functions: lmcode (24 signatures)

FunctionSignatures
lmcode_return_nulllmcode_return_null() -> void
lmcode_return_putlmcode_return_put(string, bool) -> void; lmcode_return_put(string, float) -> void; lmcode_return_put(string, FloatList) -> void; lmcode_return_put(string, FloatMap) -> void; lmcode_return_put(string, int) -> void; lmcode_return_put(string, IntList) -> void; lmcode_return_put(string, IntMap) -> void; lmcode_return_put(string, Json) -> void; lmcode_return_put(string, StrList) -> void; lmcode_return_put(string, StrMap) -> void; lmcode_return_put(string, string) -> void
lmcode_return_put_nulllmcode_return_put_null(string) -> void
lmcode_return_setlmcode_return_set(bool) -> void; lmcode_return_set(float) -> void; lmcode_return_set(FloatList) -> void; lmcode_return_set(FloatMap) -> void; lmcode_return_set(int) -> void; lmcode_return_set(IntList) -> void; lmcode_return_set(IntMap) -> void; lmcode_return_set(Json) -> void; lmcode_return_set(StrList) -> void; lmcode_return_set(StrMap) -> void; lmcode_return_set(string) -> void

Functions: math (16 signatures)

FunctionSignatures
math_absmath_abs(int) -> int; math_abs(float) -> float
math_ceilmath_ceil(int) -> int; math_ceil(float) -> float
math_floormath_floor(int) -> int; math_floor(float) -> float
math_maxmath_max(int, int) -> int; math_max(float, float) -> float
math_minmath_min(int, int) -> int; math_min(float, float) -> float
math_powmath_pow(int, int) -> int; math_pow(float, float) -> float
math_roundmath_round(int) -> int; math_round(float) -> float
math_sqrtmath_sqrt(int) -> int; math_sqrt(float) -> float

Functions: str (26 signatures)

FunctionSignatures
str_containsstr_contains(string, string) -> bool
str_ends_withstr_ends_with(string, string) -> bool
str_findstr_find(string, string) -> int
str_is_floatstr_is_float(string) -> bool
str_is_intstr_is_int(string) -> bool
str_lenstr_len(string) -> int
str_liststr_list() -> StrList
str_lowerstr_lower(string) -> string
str_mapstr_map() -> StrMap
str_matchstr_match(string, string) -> bool
str_pqstr_pq() -> StrPQ
str_queuestr_queue() -> StrQueue
str_repeatstr_repeat(string, int) -> string
str_replacestr_replace(string, string, string) -> string
str_splitstr_split(string, string) -> StrList
str_stackstr_stack() -> StrStack
str_starts_withstr_starts_with(string, string) -> bool
str_substrstr_substr(string, int, int) -> string
str_to_floatstr_to_float(string) -> float
str_to_intstr_to_int(string) -> int
str_trimstr_trim(string) -> string
str_upperstr_upper(string) -> string
str_base64_encodestr_base64_encode(string) -> string
str_base64_decodestr_base64_decode(string) -> string
str_hex_encodestr_hex_encode(string) -> string
str_hex_decodestr_hex_decode(string) -> string

Functions: other (2 signatures)

FunctionSignatures
json_parsejson_parse(string) -> Json
template_rendertemplate_render(string, Json) -> string

FloatList (7 signatures)

MethodSignatures
addadd(float) -> FloatList
atat(int) -> float
clearclear() -> FloatList
containscontains(float) -> bool
index_ofindex_of(float) -> int
lenlen() -> int
setset(int, float) -> FloatList

FloatMap (10 signatures)

MethodSignatures
lenlen() -> int
hashas(string) -> bool
getget(string) -> float
get_orget_or(string, float) -> float
setset(string, float) -> FloatMap
key_atkey_at(int) -> string
removeremove(string) -> bool
clearclear() -> FloatMap
keyskeys() -> StrList
valuesvalues() -> FloatList

FloatPQ (6 signatures)

MethodSignatures
pushpush(float, float) -> FloatPQ
poppop() -> float
peekpeek() -> float
lenlen() -> int
emptyempty() -> bool
clearclear() -> FloatPQ

FloatQueue (7 signatures)

MethodSignatures
pushpush(float) -> FloatQueue
poppop() -> float
peekpeek() -> float
lenlen() -> int
emptyempty() -> bool
clearclear() -> FloatQueue
atat(int) -> float

FloatStack (7 signatures)

MethodSignatures
pushpush(float) -> FloatStack
poppop() -> float
peekpeek() -> float
lenlen() -> int
emptyempty() -> bool
clearclear() -> FloatStack
atat(int) -> float

IntList (7 signatures)

MethodSignatures
addadd(int) -> IntList
atat(int) -> int
clearclear() -> IntList
containscontains(int) -> bool
index_ofindex_of(int) -> int
lenlen() -> int
setset(int, int) -> IntList

IntMap (10 signatures)

MethodSignatures
lenlen() -> int
hashas(string) -> bool
getget(string) -> int
get_orget_or(string, int) -> int
setset(string, int) -> IntMap
key_atkey_at(int) -> string
removeremove(string) -> bool
clearclear() -> IntMap
keyskeys() -> StrList
valuesvalues() -> IntList

IntPQ (6 signatures)

MethodSignatures
pushpush(int, float) -> IntPQ
poppop() -> int
peekpeek() -> int
lenlen() -> int
emptyempty() -> bool
clearclear() -> IntPQ

IntQueue (7 signatures)

MethodSignatures
pushpush(int) -> IntQueue
poppop() -> int
peekpeek() -> int
lenlen() -> int
emptyempty() -> bool
clearclear() -> IntQueue
atat(int) -> int

IntStack (7 signatures)

MethodSignatures
pushpush(int) -> IntStack
poppop() -> int
peekpeek() -> int
lenlen() -> int
emptyempty() -> bool
clearclear() -> IntStack
atat(int) -> int

Json (11 signatures)

MethodSignatures
kindkind() -> string
lenlen() -> int
atat(int) -> Json
getget(string) -> Json
hashas(string) -> bool
keyskeys() -> StrList
as_stringas_string() -> string
as_intas_int() -> int
as_floatas_float() -> float
as_boolas_bool() -> bool
to_jsonto_json() -> string

StrList (8 signatures)

MethodSignatures
addadd(string) -> StrList
atat(int) -> string
clearclear() -> StrList
containscontains(string) -> bool
index_ofindex_of(string) -> int
joinjoin(string) -> string
lenlen() -> int
setset(int, string) -> StrList

StrMap (10 signatures)

MethodSignatures
clearclear() -> StrMap
getget(string) -> string
get_orget_or(string, string) -> string
hashas(string) -> bool
key_atkey_at(int) -> string
lenlen() -> int
removeremove(string) -> bool
setset(string, string) -> StrMap
keyskeys() -> StrList
valuesvalues() -> StrList

StrPQ (6 signatures)

MethodSignatures
pushpush(string, float) -> StrPQ
poppop() -> string
peekpeek() -> string
lenlen() -> int
emptyempty() -> bool
clearclear() -> StrPQ

StrQueue (7 signatures)

MethodSignatures
pushpush(string) -> StrQueue
poppop() -> string
peekpeek() -> string
lenlen() -> int
emptyempty() -> bool
clearclear() -> StrQueue
atat(int) -> string

StrStack (7 signatures)

MethodSignatures
pushpush(string) -> StrStack
poppop() -> string
peekpeek() -> string
lenlen() -> int
emptyempty() -> bool
clearclear() -> StrStack
atat(int) -> string

REST and CLI interfaces

The current lmcode_std_v3 catalog (226 signatures) adds the former REST module. None of the names below exist in the std vendored by lmtorch 0.5.1; they become available when lmtorch syncs its lmcode-cpp pin and releases.

KindNames (not in lmtorch 0.5.1)
Standard interfacesRestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, RestHandler, CliCommand, CliOption
Functionsrest_config(string, string) -> void; rest_route(string, string, string) -> void; rest_serve() -> void; rest_stop() -> void; rest_cli(StrList) -> string
Exchange typeRestExchange with 15 methods