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

global variable issue #289

Open
BITACC opened this issue Jun 25, 2022 · 2 comments
Open

global variable issue #289

BITACC opened this issue Jun 25, 2022 · 2 comments

Comments

@BITACC
Copy link

BITACC commented Jun 25, 2022

Helo there, I have the following code.
a global variable that num_gpu that indicates the number of gpus availavle.
If I can data() or create_mode() separate everything is fine.
But when I call optim.minimize and pass the function, it does not see the global variable and num_gpu becomes undfined.
Am I doing something wrong?
Thanks in advance.
...

from keras import backend as K
from livelossplot import PlotLossesKeras
from hyperas import optim
from hyperas.distributions import choice, uniform
from hyperopt import Trials, STATUS_OK, tpe

# Setup (multi) GPU usage with scalable VRAM
num_gpu = setup_multi_gpus()


def data():
    print(num_gpu)

    df, train = data_import(possible_columns)
    df = prepare_data(df)

    ...
    return X_train, y_train, X_test, y_test

def create_model(X_train, y_train, X_test, y_test):
    print(num_gpu)



if __name__ == '__main__':
    best_run, best_model = optim.minimize(model=create_model, 
                                          data=data,
                                          algo=tpe.suggest,
                                          max_evals=500,
                                          trials=Trials(),
                                          eval_space=True)

    X_train, y_train, X_test, y_test = data()

    create_model(X_train, y_train, X_test, y_test )
    print(num_gpu)
@JonnoFTW
Copy link
Collaborator

Can you just call setup_multi_gpus() inside your create_model function?

You can pass the keep_temp argument to optim.minimize and examine the python file produced to see what variables are being created.

@BITACC
Copy link
Author

BITACC commented Jun 25, 2022

Yeah, that s what one should do, but the issue with not recognizing the global variable remains.

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

2 participants