Archived
- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves every shipped container - Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime - /v1/messages works with Claude Code as it ships (gearwave00001) - a long agent conversation keeps its cached history when the client rewrites its last turn (manueloverride) - a stream's first event goes out with the first token, so llama-benchy measures prefill right - opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42) - four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b) - NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA adapters (baKon) - many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool arguments and the CPU's vision and audio encoders - plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
53 lines
2.1 KiB
C++
53 lines
2.1 KiB
C++
/* token_view.h -- the sampler's VocabView over a real vocabulary (sample/vocab_view.h). */
|
|
#pragma once
|
|
#include "sample/vocab_view.h"
|
|
#include "text/tokenizer.h"
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace rad {
|
|
|
|
class TokenView final : public VocabView {
|
|
public:
|
|
/* Pieces are built once (token_piece returns a reference), saving a string per candidate per
|
|
* grammar step on the step path.
|
|
*
|
|
* They come from piece(), not Vocab::text(): text() is the vocab's own encoding (for
|
|
* byte-level BPE the GPT-2 alphabet, where a space is 'Ġ'), while piece() runs the decoder
|
|
* chain and yields the output bytes vocab_view.h asks for. With text() every grammar would
|
|
* forbid tokens containing spaces or newlines. Special tokens are rendered, because an empty
|
|
* piece would satisfy any grammar position. */
|
|
int init(std::shared_ptr<const Vocab> v) {
|
|
v_ = std::move(v);
|
|
RAD_TRY(tok_.init(v_));
|
|
pieces_.resize((size_t)v_->n_tokens());
|
|
for (int32_t i = 0; i < v_->n_tokens(); ++i)
|
|
pieces_[(size_t)i] = tok_.piece(i, /*render_special=*/true);
|
|
return RAD_OK;
|
|
}
|
|
int32_t n_tokens() const override { return v_ ? v_->n_tokens() : 0; }
|
|
const std::string& token_piece(int32_t id) const override {
|
|
static const std::string kEmpty;
|
|
return (id >= 0 && (size_t)id < pieces_.size()) ? pieces_[(size_t)id] : kEmpty;
|
|
}
|
|
bool is_eog(int32_t id) const override { return v_ && v_->is_eog(id); }
|
|
int tokenize(const std::string& s, std::vector<int32_t>* out) const override {
|
|
return out ? tok_.encode(s, *out, /*add_special=*/false, /*parse_special=*/false)
|
|
: RAD_E_INVAL;
|
|
}
|
|
int tokenize_special(const std::string& s, std::vector<int32_t>* out) const override {
|
|
return out ? tok_.encode(s, *out, /*add_special=*/false, /*parse_special=*/true)
|
|
: RAD_E_INVAL;
|
|
}
|
|
const Tokenizer& tok() const { return tok_; }
|
|
|
|
private:
|
|
std::shared_ptr<const Vocab> v_;
|
|
Tokenizer tok_;
|
|
std::vector<std::string> pieces_;
|
|
};
|
|
|
|
} /* namespace rad */
|