mialibrary
A simple library to conduct LiRA (Likelihood Ratio Attack) from Carlini et al. (2022) and RMIA (Robust Membership Inference Attack) from Zarifzadeh et al. (2024).
Core Functionality
This library takes pre-computed shadow model outputs and shadow model training indices as input and computes the likelihood ratios. Suppose we are attacking an example (x, y), the corresponding LiRA scores are defined as the likelihood ratio:
$$ \Lambda := \frac{ \mathcal{N} \big( \text{model output of } (x, y); , \mu_{\text{in}}, \sigma_{\text{in}} \big) }{ \mathcal{N} \big( \text{model output of } (x, y); , \mu_{\text{out}}, \sigma_{\text{out}} \big) } $$
The recommended shadow model output is logit computed from the predicted probabilities in the case of classifiers:
$$ \text{logit}(p) = \log\left(\frac{p}{1-p}\right) \ \text{for } p = f_\theta(x)_y $$
where $f_\theta(x)_y$ denotes the predicted probability of class $y$.
Required Input Files
The library requires two input files from a model the user attacks:
-
stat_{identifier}: Pre-computed statistics from model outputs- Format: list of NumPy arrays, NumPy arrays, or JAX arrays
- Shape of stat: (m_models, n_samples, k_augmentations)
-
in_indices_{identifier}: Training data indices- Format: list of NumPy arrays, NumPy arrays, or JAX arrays
- Shape of in_indices: (m_models, n_samples)
- Values: Boolean (True: used in training, False: not used)
Output
scores_{identifier}: LiRA scores (log-likelihood ratios)- Format: NumPy array
- Shape: (m_models, n_samples)
- Used to assess membership inference success
Basic Usage
To compute the LiRA score, use one of the following commands in your terminal:
# For standard LiRA computation using median and global variance.
python -m mialibrary.lira.process_fast_lira --data_path /path/to/data --use_median --fix_variance
In this example, scores will be calculated based on global variance and per-example median. With JAX acceleration, the score computation takes approximately 1-2 seconds, regardless of the number of CPUs.
More example usages can be found in '/examples' in the library. It also includes small data which demonstrates the score computation and how the data is expected.
Note: This library focuses solely on score computation and evaluation. Model training and statistic computation should be handled separately.
Metadata
Release files for mialibrary 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mialibrary-0.1.5.tar.gz | 3.1 MB | Without provenance | Details for mialibrary-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mialibrary-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for mialibrary-0.1.5-py3-none-any.whl |
Total release size: 6.2 MB
Release files / mialibrary-0.1.5.tar.gz
| Download URL | mialibrary-0.1.5.tar.gz |
|---|---|
| Size | 3.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d8dd88dee6e475264edd4001553baeae87695655e7332718c53a870be3b7002
|
|
BLAKE2b-256 checksum How to use checksums |
a1d335cc7012702913aa3febbb2cc89f35f366e1e348375d25d4da20545d0d4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / mialibrary-0.1.5-py3-none-any.whl
| Download URL | mialibrary-0.1.5-py3-none-any.whl |
|---|---|
| Size | 3.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
10be94d367e5a0568d6a5c58212fc20dcb093e07a63189994efe49ec3e0b06e8
|
|
BLAKE2b-256 checksum How to use checksums |
cfee3ce74e513781fa6ba758b6a7921ba43cef95a800018a22697a6fc5739744
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for mialibrary 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.