Skip to main content

Efficient MIA implementations

Project description

MIA Library

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 process_fast_lira.py --data_path {path_to_data} --filter {identifier} --fix_variance --use_median

For example:

python process_fast_lira.py --data_path data --filter patch_camelyon_vit-b-16_-1_16384_-1.0_22_22 --fix_variance --use_median

In this example, the number of shadow models is 258 and the number of samples is 32768. 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.

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.0.tar.gz (1.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.0-py3-none-any.whl (1.0 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mialibrary-0.1.0.tar.gz
  • Upload date:
  • Size: 1.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.0.tar.gz
Algorithm Hash digest
SHA256 c8fda1224f0ec7727a9344cbf806f069c3bf405ee02eea8851d1ea7881b7df71
MD5 3ee05d066e915b62443b87b763b78f54
BLAKE2b-256 c37f06f0df4d1e5c12311a117086edabccab1160d7edeaabaa3e6bff1682be29

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mialibrary-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 1.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 059113b67fbd16f6c9ee051427949c3b5f87a8c6e18d23c7403a48ddb35261e3
MD5 99bf2747b45c19ff34262055b1e7391a
BLAKE2b-256 850adc13ea0f0df9198ed40c9d02e6f4eaa41e9930455aa116853478fb818923

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