---
title: "ClikaRT::nn::QEmbedding"
sidebar_label: "QEmbedding"
description: "Quantized embedding-table module: gathers rows of a packed table by token index and decodes them to float. The table is [V, E] (one row per vocabulary entry); forward(ids) returns ids.shape ++ [E]."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/nn/qembedding.h`  
**Inherits:** [`ClikaRT::nn::Module`](./Module.md)

Quantized embedding-table module: gathers rows of a packed table by token index and decodes them to float.

The table is `[V, E]` (one row per vocabulary entry); `forward(ids)` returns `ids.shape ++ [E]`. The codes are never densely materialized: the gather decodes the rows it reads. A dense table is [`Embedding`](./Embedding.md)'s.

```cpp
auto emb = ClikaRT::nn::QEmbedding::make(weight);   // a QTensor
auto h   = emb->forward(token_ids);                  // [B, S] -> [B, S, E]
```

## Static member functions

### make(QTensor, QEmbeddingOptions) {#make}

<div class="api-signature">

`static` `std::shared_ptr<QEmbedding>` **`make`**([`QTensor`](../QTensor.md) `weight`, [`QEmbeddingOptions`](./QEmbeddingOptions.md) `options` `=` `{}`)

</div>

Defaults: every option at its default ([`QEmbeddingOptions`](./QEmbeddingOptions.md)).

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 81

</div>

### make(int64\_t, int64\_t, QEmbeddingOptions) {#make-2}

<div class="api-signature">

`static` `std::shared_ptr<QEmbedding>` **`make`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::int64_t` `num_embeddings`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::int64_t` `embedding_dim`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`QEmbeddingOptions`](./QEmbeddingOptions.md) `options` `=` `{}`<br />
)

</div>

Defaults: every option at its default ([`QEmbeddingOptions`](./QEmbeddingOptions.md)).

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 95

</div>

## Member functions

### set\_weights() {#set_weights}

<div class="api-signature">

`void` **`set_weights`**([`QTensor`](../QTensor.md) `weight`)

</div>

Bind the `weight` slot: a quantized payload whose logical shape is the declared `[`[`num_embeddings`](./QEmbedding.md#num_embeddings)`, `[`embedding_dim`](./QEmbedding.md#embedding_dim)`]`; the declared placement wins; the codes are never cast. Re-binding drops the built lookup; the next [`forward`](./QEmbedding.md#forward) rebuilds. Raises [`ClikaRT::Error`](../Error.md) on a geometry mismatch or a weight without a scheme.

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 107

</div>

### \~QEmbedding() {#QEmbedding}

<div class="api-signature">

**`~QEmbedding`**() `override`

</div>

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 111

</div>

### to\_impl(StreamOrDevice) {#to_impl}

<div class="api-signature">

`virtual` [`Result`](../Result.md)`<void>` **`to_impl`**([`StreamOrDevice`](../StreamOrDevice.md) `where`) `override`

</div>

Move to a placement ([`Device`](../Device.md) / [`Stream`](../Stream.md)): the packed table moves with the module.

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 115

</div>

### to\_impl(DataType) {#to_impl-2}

<div class="api-signature">

`virtual` [`Result`](../Result.md)`<void>` **`to_impl`**([`DataType`](../../index.md#DataType) `dtype`) `override`

</div>

The weight stays quantized at rest: a dtype move is `Unsupported` (decode explicitly, [`ops::dequantize`](../ops/dequantize.md#dequantize), when a dense copy is wanted).

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 118

</div>

### forward() {#forward}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`forward`**([`Tensor`](../Tensor.md) `ids`) `const`

</div>

[`forward_impl`](./QEmbedding.md#forward), unwrapped: raises [`ClikaRT::Error`](../Error.md) on failure.

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 127

</div>

### operator()() {#operator-call}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`operator()`**([`Tensor`](../Tensor.md) `ids`) `const`

</div>

Same as [`forward`](./QEmbedding.md#forward).

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 131

</div>

### num\_embeddings() {#num_embeddings}

<div class="api-signature">

`std::int64_t` **`num_embeddings`**() `const noexcept`

</div>

The declared row count.

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 136

</div>

### embedding\_dim() {#embedding_dim}

<div class="api-signature">

`std::int64_t` **`embedding_dim`**() `const noexcept`

</div>

The declared row length.

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 138

</div>

### options() {#options}

<div class="api-signature">

`const` [`QEmbeddingOptions`](./QEmbeddingOptions.md)`&` **`options`**() `const noexcept`

</div>

The settings this module was made with.

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 140

</div>

## Protected member functions

### initialize\_impl() {#initialize_impl}

<div class="api-signature">

`virtual` [`Result`](../Result.md)`<void>` **`initialize_impl`**() `override`

</div>

The pack hook ([`Module::initialize_impl`](./Module.md#initialize_impl)): builds the lookup now (idempotent, thread-safe). The `weight` slot must be bound; a still-declared slot is a clean error. After the build the registry slot reads back from the packed table.

<div class="api-declared">

Declared in `ClikaRT/nn/qembedding.h`, line 152

</div>
