Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize object params before they get logged from argument-free classes #19772

Open
V0XNIHILI opened this issue Apr 12, 2024 · 0 comments · May be fixed by #19771
Open

Sanitize object params before they get logged from argument-free classes #19772

V0XNIHILI opened this issue Apr 12, 2024 · 0 comments · May be fixed by #19771
Labels
feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers

Comments

@V0XNIHILI
Copy link

V0XNIHILI commented Apr 12, 2024

Description & Motivation

The motivation for this proposal is as follows: when you store classes (not-yet instantiated, but from the main file) in a module's hyperparameters to instantiate them later, the related entries in the dictionary are not sanitized.

Pitch

For example, let's say my configuration is this:

class Stepper():
    def __init__(self):
        self.scale = 3

    def step(self):
        return self.scale

config = {
    "stepper": Stepper
}

Then I want the hyperparameters that will be logged to look like this:

config = {
    "criterion": "Stepper"
}

And not like this:

config = {
    "criterion": "<__main__.Stepper object at 0x352255190>"
}

Alternatives

When a module has at least one __init__ argument, this problem doesn't exist:

class Stepper:
    def __init__(self, scale):
        self.scale = scale

    def forward(self, x):
        return self.scale * x

config = {
    "stepper": Stepper,
    "config": {"scale": 0.0001}
}

Results in a logged configuration dictionary of form:

config = {
    "criterion": "Stepper",
    "config": {"scale": 0.0001}
}

Additional context

No response

cc @Borda

@V0XNIHILI V0XNIHILI added feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers labels Apr 12, 2024
@V0XNIHILI V0XNIHILI linked a pull request Apr 12, 2024 that will close this issue
11 tasks
@V0XNIHILI V0XNIHILI changed the title Sanitize object params before they get logged Sanitize object params before they get logged from argument-free classes Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant