Skip to main content

Efficient MIA implementations

Project description

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.

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

mialibrary-0.1.5.tar.gz (3.1 MB view details)

Uploaded Source

Built Distribution

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

mialibrary-0.1.5-py3-none-any.whl (3.1 MB view details)

Uploaded Python 3

File details

Details for the file mialibrary-0.1.5.tar.gz.

File metadata

  • Download URL: mialibrary-0.1.5.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for mialibrary-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3d8dd88dee6e475264edd4001553baeae87695655e7332718c53a870be3b7002
MD5 79cd8111dcc25a1ecc02a6b76a40f9c2
BLAKE2b-256 a1d335cc7012702913aa3febbb2cc89f35f366e1e348375d25d4da20545d0d4c

See more details on using hashes here.

File details

Details for the file mialibrary-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: mialibrary-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for mialibrary-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 10be94d367e5a0568d6a5c58212fc20dcb093e07a63189994efe49ec3e0b06e8
MD5 d2a6f63b90bb3a9f9cedcaf13a022098
BLAKE2b-256 cfee3ce74e513781fa6ba758b6a7921ba43cef95a800018a22697a6fc5739744

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