Skip to content

add saving and loading infairness component state to disk#57

Merged
MayankAgarwal merged 2 commits intomainfrom
iss56-save
Sep 20, 2022
Merged

add saving and loading infairness component state to disk#57
MayankAgarwal merged 2 commits intomainfrom
iss56-save

Conversation

@MayankAgarwal
Copy link
Member

@MayankAgarwal MayankAgarwal commented Sep 14, 2022

fixes #56

This PR adds support for saving and loading trained distance metrics to disk. The format is the same as PyTorch modules, like:

dist = distances.SVDSensitiveSubspaceDistance()   # can be any metric
dist.fit(*args, **kwargs)

# saving state to disk
state = dist.state_dict()
torch.save(state, PATH)

# load state from disk
state = torch.load(PATH)
dist = distances.SVDSensitiveSubspaceDistance()
dist.load_state_dict(state)

Refer: https://pytorch.org/tutorials/beginner/saving_loading_models.html#saving-loading-model-for-inference

@MayankAgarwal MayankAgarwal self-assigned this Sep 16, 2022
@MayankAgarwal MayankAgarwal added the enhancement New feature or request label Sep 16, 2022
@MayankAgarwal MayankAgarwal marked this pull request as ready for review September 16, 2022 19:00
Copy link

@moonfolk moonfolk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a way to access logistic regression coefficients (including bias - it is often useful to check LR accuracy when learning the fair metric) in this PR or do you want to do a different PR for it? I am suggesting it here since we also want to save it along with sigma probably?
Another comment, which could be a separate PR, we want to provide additional input arguments when fitting LR such as optimizing for balanced accuracy via class_weight='balanced'.

@MayankAgarwal MayankAgarwal merged commit 54f727f into main Sep 20, 2022
@MayankAgarwal MayankAgarwal deleted the iss56-save branch September 20, 2022 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allow saving and loading inFairness models to disk

2 participants