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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mialibrary-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 7ced2cd26aeb80720a8110499e332d51668a710e3e158d0163afdbb5a9f8e41c
MD5 a26f7266e5c49051954fe19019221421
BLAKE2b-256 4cd029672229150b2bae92aa0d7d05aafa822cf7de590f29040f402af5848e6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mialibrary-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5008e22693813485e16afc7425aa57096257b05cb554a1b6967f91c1e32a9db2
MD5 f73bb34712636b93f5b925827b80d5b4
BLAKE2b-256 dba8816d0f7907871ad3ffaa946787c46c8417064b719157f4739bf39fa75b2f

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