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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mialibrary-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 34353e3a5a6550730a2bf6f7c662f640aa8cb5560761d5c85a5f747ae0f84dc2
MD5 0214d0f2a92b372805c9a47d7ca448cb
BLAKE2b-256 64c62b8781eaa1bb33135de43aa7b655bbf187a6c593657b0384aacec2628a15

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mialibrary-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2527526ab2bceba2ecf4eb9710a7a6ee10867fb1cf900fa5b626c9efb02a141a
MD5 7bb829b7d64e8bde796d48148b8e29ba
BLAKE2b-256 84beba36df80c1035d2455e4e58dc8c49ceb4db53f9753e0382e194fa2db5a97

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