Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

laghu

Latest version: v0.4.2

Overview

Last scanned
25 Nov 2026
Published
25 Nov 2026
PyPI package Publisher: karthik777
0 Stars
0 Forks
7 Versions
2.5K Downloads
Jupyter Notebook Repo language

Scan summary

laghu was last scanned on 25 Nov 2026 at version 0.4.2. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 7 versions; the latest 2 were published within 7 days (19–25 Nov 2026).
  • Findings: No rules fired in version 0.4.2.
  • Downloads: 2,546 downloads.

Versions

7 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.4.2 LATEST 25 Nov 2026 No rules fired
0.4.1 19 Nov 2026 No rules fired
0.4.0 24 Oct 2026 No rules fired
0.3.1 23 Oct 2026 Not shown
0.3.0 23 Oct 2026 Not shown

No rules fired in 0.4.2

Findings

Findings for v0.4.2. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 0.4.2; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

laghu

model2vec makes static embedding models. A static embedding model changes a text into a vector. It splits the text into tokens. It finds a stored vector for each token. Then it calculates the average of these vectors. No neural network runs, so these models are very fast. Each model has two main parts: an embedding table with one row for each token, and a tokenizer that splits text into tokens.

laghu (लघु, Sanskrit for “light”) loads the same models with much less memory. It gives the same vectors as model2vec, bit for bit. A model that laghu loads has the same encode, encode_as_sequence and tokenize methods as a model2vec model. The section What is not supported gives the differences.

Where the memory goes

A process is one running program. Private memory is memory that only one process can use. model2vec copies two large parts of the model into the private memory of each process. laghu shares these parts between processes.

Part of potion-multilingual-128M model2vec laghu
Embedding table 512 MB, copied into each process Mapped from model.safetensors and shared
Tokenizer search structure for 500,353 pieces About 610 MB in each process Mapped from a vocabulary file and shared
Private memory after encode About 1.3 GB About 60 MB, mostly Python and its imports

laghu maps the embedding table from the file. The operating system reads a page of the file only when laghu uses it. The operating system keeps the page in its cache. It shares the page with every process that maps the same file. When memory is low, the operating system can remove the page and read it again later.

For a Unigram model, laghu also replaces the search structure of the tokenizer. A Unigram tokenizer selects the most likely sequence of pieces from a long list. laghu builds a vocabulary file one time for each tokenizer.json. The file holds the pieces in a compact marisa trie, with their ids and scores. Every process maps this file and shares it. laghu then finds the best pieces with a Viterbi search. The search is written in Python. With the optional laghu-rs wheel, the search runs in Rust. The text normalization and the first split into words come from tokenizers. laghu builds them from the same tokenizer.json, without the vocabulary.

Models with a BPE or WordLevel tokenizer use tokenizers to tokenize. WordPiece models also use tokenizers when laghu-rs is not installed. laghu maps the table of these models too. The memory that you save depends on the size of the table compared with the size of the tokenizer.

Install

uv add laghu        # or: pip install laghu

model2vec is not a dependency. Install the fallback extra, uv add 'laghu[fallback]', in these two cases:

The extra installs model2vec 0.9, which laghu matches. model2vec 0.10 gives different vectors, and its tokenize does not take max_length.

The optional Rust core is the wheel laghu-rs (module laghu_rs). It needs Python 3.11 or later. Install it with pip install laghu-rs, or with the extra: uv add 'laghu[rust]'.

The optional Rust core

With laghu-rs installed, laghu tokenizes these models in Rust, on all CPU cores:

  • Unigram models. laghu_rs normalizes the text, finds the added tokens and splits the text into words with the tokenizers crate. Then it runs the Viterbi search of laghu over a byte trie in the shared vocabulary file.
  • WordPiece models that have a BertNormalizer, a BertPreTokenizer and a WordPiece model. The English potion models are examples. laghu_rs.WordPiece is a port of FastWordPiece from model2vec-rs. It calculates only the token ids. It does not calculate the offsets that tokenizers keeps.

For a float32 table without weights or a token mapping, laghu_rs also calculates the average vectors. On every path, the ids and vectors are the same as the ids and vectors of model2vec, bit for bit, except for a tokenizer.json that pads (see What is not supported).

This table gives the speed and the private memory for 500-character chunks of text. The computer was an M3 Max with 14 cores. The measurements are from 2026-10-24, with a load average of 6.5 to 9. Each speed is the best of three runs of laghu.bench.speed.

Model Loader Chunks per second Private memory
potion-multilingual-128M (Unigram) laghu with laghu-rs 42,385 72 MB
laghu without laghu-rs 1,940 67 MB
model2vec 0.9 21,105 1,369 MB
potion-base-8M (WordPiece) laghu with laghu-rs 432,938 81 MB
laghu without laghu-rs 55,514 93 MB
model2vec 0.9 55,600 140 MB
potion-code-16M-v2 (WordPiece, float16) laghu with laghu-rs 85,164 126 MB
laghu without laghu-rs 57,367 109 MB
model2vec 0.9 21,485 144 MB

The potion-code-16M-v2 rows are from 2026-11-25, with a load average of 6.7, and laghu-rs 0.2.3. laghu-rs tokenizes this model, and numpy calculates the average, because the table is float16. model2vec 0.9 pads each text in a batch to the longest text, so it does more work.

laghu 0.3.0 gave 5,276 chunks per second for model2vec on potion-multilingual-128M. That number was measured with tokenizers on one core, probably because TOKENIZERS_PARALLELISM=false was set. On one core, model2vec gives 5,462 chunks per second on the same computer.

When laghu does not use Rust

For a Unigram model, laghu tokenizes in pure Python when one of these conditions is true:

  • laghu cannot import laghu_rs.
  • LAGHU_RUST=0 is set when the model loads.
  • The model loads with shared=False.
  • The tokenizer.json truncates or pads.

For a Unigram model, laghu splits the text in Python and does the search in Rust when one of these conditions is true:

  • The Python tokenizers has a different major or minor version from laghu_rs.TOKENIZERS. A different patch version is accepted. laghu-rs 0.1.0 and 0.2.0 use tokenizers 0.23.2. They accept all Python tokenizers 0.23.x versions.
  • The tokenizers crate cannot read the tokenizer.json.
  • The crate splits a text in PROBE differently from the Python split of laghu. PROBE is a set of 46 difficult test texts. laghu logs a warning.

laghu tokenizes a WordPiece model with tokenizers when one of these conditions is true:

  • laghu cannot import laghu_rs, or laghu_rs has no WordPiece.
  • LAGHU_RUST=0 is set when the model loads.
  • The model loads with lean=False.
  • The Python tokenizers has a different major or minor version from laghu_rs.TOKENIZERS.
  • The normalizer, pre-tokenizer and model are not BertNormalizer, BertPreTokenizer and WordPiece.
  • The unknown token is not in the vocabulary.
  • An added token is normalized, or has lstrip, rstrip or single_word set, and laghu-rs is older than 0.2.3.
  • laghu_rs.WordPiece gives different ids from tokenizers on a text in PROBE. laghu logs a warning.

From laghu-rs 0.2.3, the tokenizers crate finds the added tokens of a WordPiece model when an added token is normalized, or has lstrip, rstrip or single_word set. This applies the four settings as tokenizers does. It is slower than the search of laghu_rs for other added tokens. potion-code-16M-v2 has such a token, [PAD].

laghu does not use laghu-rs for BPE and WordLevel models. It does not use laghu-rs for Unigram models with a feature that laghu does not copy.

The ids are the same on every path.

Use

from laghu import load

m = load('minishlab/potion-multilingual-128M')      # a folder, or a Hugging Face repo id (the local cache is tried first)
v = m.encode(['The quick brown fox.', 'कर्मण्येवाधिकारस्ते'])   # float32, (2, 256), unit rows: the same array model2vec returns
m.tokenize(['hello world'])
m.encode_as_sequence('hello world').shape          # (n_tokens, 256)
(2, 256)

load takes a local folder or a Hugging Face repo id. It returns a LeanModel. If the repo is in the local Hugging Face cache, load does not use the network.

If laghu cannot load the model, load logs the reason. Then it tries model2vec’s StaticModel, which needs laghu[fallback]. If model2vec also fails, load raises the first error from laghu. Use fallback=False to get the error without a try with model2vec.

laghu and model2vec cannot read tables stored as bfloat16 or float8, because numpy does not have these types.

laghu keeps the vocabulary file of a Unigram model in $LAGHU_CACHE. If $LAGHU_CACHE is not set, laghu uses $XDG_CACHE_HOME/laghu. If that is not set, laghu uses ~/.cache/laghu. If laghu cannot write to the folder, it puts the file next to tokenizer.json.

Vocabulary file Time
First load, which builds the file 1 to 2 seconds
Later loads, in any process, which map the file A few hundredths of a second

If tokenizer.json changes, or if the file is damaged, laghu builds the file again. load(..., shared=False) keeps the vocabulary in a Python dict. This uses about 80 MB more private memory in each process.

To check your own model, use same_as_model2vec(path). It loads the model with laghu and with model2vec, and it compares the results. It uses the built-in test texts of laghu, or the texts that you give:

from laghu import same_as_model2vec
same_as_model2vec('minishlab/potion-base-8M', ['my', 'own texts'])
/Users/71293/code/personal/orgs/laghu/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

{'lean': False,
 'n': 2,
 'ids': True,
 'dtype': True,
 'f32': True,
 'f16': True,
 'exact': True,
 'seq': True,
 'median': True,
 'unk': True,
 'tokens': True}

The result shows, for each check, if the two loaders agree:

Key What it checks
ids The token ids
f32 The vectors, changed to float32
f16 The vectors, changed to float16
dtype The exact data type
exact The exact bits
seq encode_as_sequence
median median_token_length
unk The unknown token id
tokens The token list
lean laghu used its own Unigram tokenizer (not a check)
n The number of texts (not a check)

What matches, and what it costs

Every model in the table below gives the same ids and vectors as model2vec, bit for bit, on 4,726 texts. The texts include prose in 36 languages and random strings from 30 Unicode blocks. They also include control characters, special tokens, emoji sequences, combining marks, bidirectional text controls and a string of 200,000 characters.

These rules apply to the table:

  • Each memory number comes from a new process. On macOS, private memory is phys_footprint after encode, and peak memory is lifetime_max_phys_footprint. On Linux, the same columns would hold RssAnon and VmHWM.
  • Speed is encode over 3,226 texts on an M3 Max.
  • “laghu tokenizes with” gives the tokenizer that laghu used: its Viterbi search in Python, its Viterbi search in Rust with laghu-rs, or tokenizers.
  • In the private memory and speed columns, the first two numbers were measured without laghu-rs. The third number was measured with laghu-rs, in the same way.
  • — means that laghu-rs does not change the row. This is true for BPE and WordLevel models.
  • “not measured” means that nobody measured the row with laghu-rs. These rows were checked without laghu-rs. With laghu-rs, they use Rust when their tokenizer qualifies.
  • potion-base-8M and potion-code-16M-v2 were checked again with laghu-rs on 2026-10-24. Both stay identical.
  • From laghu 0.4.2, potion-code-16M-v2 gives the vectors of model2vec 0.9 for each text alone, not for a batch. The section What is not supported tells why. The row was measured before this change.

The laghu-rs numbers come from different sessions than the older numbers. Compare each laghu-rs number with the numbers from its own session:

Model Date model2vec, texts per second laghu without laghu-rs, texts per second laghu with laghu-rs, texts per second Notes
potion-multilingual-128M 2026-10-23 22,846 14,859 130,007 Best of 3 runs. Load average 6.5. The slowest Rust run gave 41,988 texts per second.
potion-base-8M 2026-10-24 82,027 not measured 650,395 Best of 3 runs. Each Rust run took about 0.003 seconds.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • pypi-releases laghu

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Vulnerability Insights

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?

Microsoft's Official agent framework Hijacked
AI & VibeSec

BREAKING: Hijacked Releases of Microsoft’s Official agent-framework Steals Azure and CI Credentials

PHP2Shell, Day 5 93.6% of Measurable Instances Still Unpatched (1)
Vulnerability Insights

PHP2Shell, Day 5: The Panic Hasn’t Turned Into Patching

Frame 2085668439 (1)
Group 1261154229