# gizai/models/motionbricks/model

NVIDIA's MotionBricks (MotionBricks-SOMA-RP-v1), a person's motion between poses: from four frames so far and up to four target frames, the frames between them, 24 to 64 at 30 a second, as NVlabs/motionbricks computes it. A token is 4 frames. The root model reads the eight frames and picks how many tokens the motion takes (6 to 16) and the root's path; the pose model (a transformer of 16 layers) picks each token's codes (5 heads of 16) in one step; the VQ-VAE's decoder turns the codes into frames, held to the given frames. Many motions run in one batch. The frames are SOMA's features (gizai/models/soma), as ARDY's are.

```gizlang
import * as Model from "gizai/models/motionbricks/model";
```

## Types

### `Bricks`

```gizlang
type Bricks = { gpu: Gpu; w: Map<string, Tensor>; shared: Vec<Layer>; rootTokens: Vec<Layer>; poseLayers: Vec<Layer>; codes: Tensor; masked: Tensor; mean: Vec<f64>; scale: Vec<f64>; stages: Ref<Map<string, Stage>>; }
```

MotionBricks on a GPU: its weights by name ("pose.", "root.", "vq." and the checkpoint's names after mmm_net. or
pose_net.), the root model's and the pose model's layers, the codebook ([HEADS CODES + 1, CODE], a zero row last), the pose model's
embedding of a token of mask codes (a token's 4 frames x 160) and the statistics of the features (global root 5,
local root 4, body 361), and the recorded stages of its batches (Bricks.staged).

- `gpu`: `M7.Gpu`
- `w`: `_gizlang_sdk_collections.Map<string, _gizlang_lib_ai__tensor__storage.Tensor<f32>>`
- `shared`: `Vec<_gizlang_lib_ai__netops__encoder.Layer>`
- `rootTokens`: `Vec<_gizlang_lib_ai__netops__encoder.Layer>`
- `poseLayers`: `Vec<_gizlang_lib_ai__netops__encoder.Layer>`
- `codes`: `_gizlang_lib_ai__tensor__storage.Tensor<f32>`
- `masked`: `_gizlang_lib_ai__tensor__storage.Tensor<f32>`
- `mean`: `Vec<f64>`
- `scale`: `Vec<f64>`
- `stages`: `Ref<_gizlang_sdk_collections.Map<string, M83.Stage>>`

### `Ask`

```gizlang
type Ask = { frames: Vec<f64>; root: Vec<bool>; velocity: Vec<bool>; pose: Vec<bool>; counts: Vec<i64>; }
```

A motion asked for: SLOTS frames of SOMA's features (REP values each, in the world: the four frames so far, then
the targets), whether each slot gives its root's place and heading, its root's velocity and height, and its pose
(the four frames so far give all three), and the token counts allowed (FEWEST.. MOST; none: all).

- `frames`: `Vec<f64>`
- `root`: `Vec<bool>`
- `velocity`: `Vec<bool>`
- `pose`: `Vec<bool>`
- `counts`: `Vec<i64>`

### `Made`

```gizlang
type Made = { frames: Vec<f64>; tokens: i64; }
```

A motion made: its frames (TOKEN x tokens, REP values each, in the world). Its first token's frames are the frames
so far, its last token's the targets.

- `frames`: `Vec<f64>`
- `tokens`: `i64`

## Functions

### `load`

```gizlang
function load(folder: string, gpu: Gpu): Bricks throws string
```

MotionBricks of `folder` (FOLDER of nvidia/MotionBricks: its three parts' checkpoints and statistics) on `gpu`.

Effects: fail, read, write, console, io, alloc.

### `played`

```gizlang
function played(made: Made, a: Ask): Frames
```

The frames to play of motion `made` made for ask `a` (gizlang/retarget's, of SOMA's skeleton), as the reference's
engine gives them: from the last frame so far to the first target (TOKEN - 1 frames cut at each end), each joint's
turn and the root's place moved by a correction that fades over the motion, so the first frame is the last frame so
far and the last frame the first target (its turns where it gives a pose, its place where it gives a root). The
model holds the frames given only within centimeters.

Effects: fail, read, write, console, io, alloc.

## Methods

### `Bricks.made`

```gizlang
function Bricks.made(self: Bricks, asks: Vec<Ask>): Vec<Made> throws string
```

The motions of `asks`, in one batch.

Effects: fail, read, write, console, io, alloc.

## Constants

### `TOKEN`

```gizlang
const TOKEN: i64 = 4
```

A token's frames.

### `SLOTS`

```gizlang
const SLOTS: i64 = 8
```

The frames given: four so far, then four targets.

### `FEWEST`

```gizlang
const FEWEST: i64 = 6
```

The fewest tokens of a motion.

### `MOST`

```gizlang
const MOST: i64 = 16
```

The most tokens of a motion.

### `FOLDER`

```gizlang
const FOLDER = "soma/soma-v6-nova-4n8g-ea43dd8-fp32-v1"
```

The checkpoint's folder (in nvidia/MotionBricks), and its three parts.

