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

Preprocessor refactoring #220

Open
younik opened this issue Nov 17, 2024 · 2 comments
Open

Preprocessor refactoring #220

younik opened this issue Nov 17, 2024 · 2 comments

Comments

@younik
Copy link
Collaborator

younik commented Nov 17, 2024

I believe preprocessors should not be part of the Env class, and they should kept separate.

  1. These lines in env examples don't scale well:

    if preprocessor_name == "Identity":
    preprocessor = IdentityPreprocessor(output_dim=ndim)
    elif preprocessor_name == "KHot":
    preprocessor = KHotPreprocessor(height=height, ndim=ndim)
    elif preprocessor_name == "OneHot":
    preprocessor = OneHotPreprocessor(
    n_states=self.n_states,
    get_states_indices=self.get_states_indices,
    )
    elif preprocessor_name == "Enum":
    preprocessor = EnumPreprocessor(
    get_states_indices=self.get_states_indices,
    )
    else:
    raise ValueError(f"Unknown preprocessor {preprocessor_name}")

  2. It seems they are not used inside the env class, but they are just passed to GFNModule, which is a better location.

env = Box()
module = BoxPFMLP(
hidden_dim=32, n_hidden_layers=2, n_components=1, n_components_s0=1
)
estimator = DiscretePolicyEstimator(
module, n_actions=2, preprocessor=env.preprocessor
)

I believe they should be instantiated by the user and eventually passed to GFNModule.

@josephdviviano
Copy link
Collaborator

josephdviviano commented Nov 17, 2024 via email

@saleml
Copy link
Collaborator

saleml commented Nov 26, 2024

By the way, this was the case 2 years ago. In fact, back then, we used to define an Estimator as a GFModule + Preprocessor object: https://github.com/GFNOrg/torchgfn/blob/7ac7de2a39e6bf6ca36985a3762fcef63d57bb56/gfn/estimators.py

This big commit, which is actually more of a code restructure than a mere commit, changed that. I had put the preprocessor in the environment.

Given the current structure of the code base, and the fact that Estimators are not a thing anymore, I agree with with your suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants