Skip to main content

The EmbeddingRWKV Model

Project description

The EmbeddingRWKV Model

https://github.com/howard-hou/EmbeddingRWKV

Tokenizer

import os
from rwkv_emb.tokenizer import RWKVTokenizer

# 1. 
tokenizer = RWKVTokenizer()

# 2. add_eos should be True for embedding inference to append the EOS token (65535)
text = "hello world"
tokens = tokenizer.encode(text, add_eos=True)

print(tokens)
# 输出: [token_id, ..., 65535]

The encode method returns a list of integers. For embedding inference, append the end-of-sequence token (65535) to mark completion before feeding the tokens to the model.

# !!! set these before import RWKV !!!
import os

os.environ["RWKV_CUDA_ON"] = '1'  # '1' to compile CUDA kernel (10x faster), requires c++ compiler & cuda libraries

from rwkv_emb.model import EmbeddingRWKV

EOS_INDEX = 65535

# download models: to be announced
model = EmbeddingRWKV(model_path='path-to-model')

# !!! model.forward(tokens, state) will modify state in-place !!!
# single-sample inference
emb, state = model.forward([187, 510, 1563, 310, 247, EOS_INDEX], None)
print(emb.detach().cpu().numpy())                   # get logits

# streaming a single sequence
emb, state = model.forward([187, 510], None)
emb, state = model.forward([1563], state)           # RNN has state (use deepcopy to clone states)
emb, state = model.forward([310, 247, EOS_INDEX], state)
print(emb.detach().cpu().numpy())                   # same result as above

# batch inference (all sequences must share the same length)
batch_tokens = [
    [187, 510, 1563, 310],
    [247, EOS_INDEX, 187, 310],
]
emb_batch, batch_state = model.forward(batch_tokens, None, full_output=False)
print(emb_batch.detach().cpu().numpy())             # shape: [batch, n_vocab]
print(len(batch_state), batch_state[-2].shape)      # batched state shapes
print('\n')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rwkv_emb-0.0.5.tar.gz (394.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rwkv_emb-0.0.5-py3-none-any.whl (394.3 kB view details)

Uploaded Python 3

File details

Details for the file rwkv_emb-0.0.5.tar.gz.

File metadata

  • Download URL: rwkv_emb-0.0.5.tar.gz
  • Upload date:
  • Size: 394.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rwkv_emb-0.0.5.tar.gz
Algorithm Hash digest
SHA256 ea5039acd9a22dc02a3f03c1ce90c93ffa458b0f2a8e9c18fe1036cf30070561
MD5 01dc512fc819efb3bee7c2471b071aca
BLAKE2b-256 5a05a58474c45e28b4f6c0317222862f6fcddd1d1335d6e8dbf48898d6fe6782

See more details on using hashes here.

File details

Details for the file rwkv_emb-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: rwkv_emb-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 394.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rwkv_emb-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 eaaf0007b0118d09e38be81eebf735e3b12c7c43ddf55b4dc74e4c7a9a14c6e2
MD5 eab30c8321aa5e164f7311c69df40d23
BLAKE2b-256 409be80b0a8f4f4b615c2925b9f13603743fea300d063d9eaa8458d8672697c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page