Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Can't use powershell to run config with my own code #4452

Closed
DoveEchoing opened this issue Jan 7, 2022 · 4 comments
Closed

Can't use powershell to run config with my own code #4452

DoveEchoing opened this issue Jan 7, 2022 · 4 comments
Assignees

Comments

@DoveEchoing
Copy link

DoveEchoing commented Jan 7, 2022

Describe the issue:
I can use the source code to run nni on my computer,but when I was trying to modify the code to meet my needs,it occurred some mistakes. I referred some examples to modify my code(like regression/classification of sklearn,mnist-keras),because the framework is different,when I first try to modify my code and use powershell to run it,it occurred a lot mistakes.
Today I modified my code once again,it could run successfully in pycharm,but it failed in powershell.
crying,I think I need some help.

Environment:

  • NNI version:2.5
  • Training service (local|remote|pai|aml|etc):local
  • Client OS:Windows 10
  • Server OS (for remote mode only):None
  • Python version:3.6
  • PyTorch/TensorFlow version:1.10.1/2.6.2
  • Is conda/virtualenv/venv used?:conda
  • Is running in Docker?:no

code

LOG = logging.getLogger('ANN Example')

def load_data(train_path='./data/data712pc_train.csv', test_path='./data/data712pc_test.csv'):
    InputIndex = ['X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9', 'X10',
                  'X11', 'X12', 'X13', 'X14', 'X15']
    OutputIndex = ['Y']
    data_train = pd.read_csv(train_path)
    train_X = data_train[InputIndex]
    train_Y = data_train[OutputIndex]
    data_test = pd.read_csv(test_path)
    test_X = data_test[InputIndex]
    test_Y = data_test[OutputIndex]
    minmax = MinMaxScaler(feature_range=(0, 1))
    X_train = minmax.fit_transform(train_X)
    X_test = minmax.transform(test_X)
    Y_train = minmax.fit_transform(train_Y)
    Y_test = minmax.transform(test_Y)
    return X_train, X_test, Y_train, Y_test

def default_params():
    params = {
        'activation': 'relu',
        'optimizer': 'Adam',
        'learning_rate': 0.001,
        'momentum': 0.9
    }
    return params

def create_model(PARAMS):
    layers = [
        Dense(8, activation=PARAMS.get('activation')),
        Dense(4, activation=PARAMS.get('activation')),
        Dense(1, activation=PARAMS.get('activation'))
    ]
    model = Sequential(layers)

    if PARAMS.get('optimizer') == 'Adam':
        optimizer = Adam(lr = PARAMS.get('learning_rate'))
    elif PARAMS.get('optimizer') == 'SGD':
        optimizer = SGD(lr = PARAMS.get('learning_rate'), momentum = PARAMS.get('momentum'))
    else:
        optimizer = RMSprop(lr = PARAMS.get('learning_rate'), momentum = PARAMS.get('momentum'))

    model.compile(loss=keras.losses.mean_squared_error, optimizer=optimizer)

    return model

def run(X_train, X_test, Y_train, Y_test, model):
    model.fit(X_train, Y_train, batch_size=64, epochs=100, verbose=1)
    loss = model.evaluate(X_test, Y_test, verbose=0)
    y_pred = model.predict(X_test)
    rmse = mean_squared_error(Y_test, y_pred) ** 0.5
    print('The rmse of prediction is:', rmse)
    nni.report_final_result(rmse)

if __name__ == '__main__':
    X_train, X_test, Y_train, Y_test = load_data()

    try:
        # get parameters from tuner
        RECEIVED_PARAMS = nni.get_next_parameter()
        LOG.debug(RECEIVED_PARAMS)
        PARAMS = default_params()
        PARAMS.update(RECEIVED_PARAMS)
        LOG.debug(PARAMS)
        model = create_model(PARAMS)
        run(X_train, X_test, Y_train, Y_test, model)
    except Exception as exception:
        LOG.exception(exception)
        raise

search space
search space

config
config_windows

some files
file

error
error

@liuzhe-lz
Copy link
Contributor

NNI uses PyYAML to parse config files which... unfortunately has some strange limitations.
We are fixing this for next release.
For now you can replace tabs in your search space file with spaces and it should work.

@liuzhe-lz liuzhe-lz self-assigned this Jan 7, 2022
@DoveEchoing
Copy link
Author

NNI uses PyYAML to parse config files which... unfortunately has some strange limitations. We are fixing this for next release. For now you can replace tabs in your search space file with spaces and it should work.

Does it mean that I need to replace "sigmoid" or others with space?
or replace "momentum" (and others) with space?

@liuzhe-lz
Copy link
Contributor

I mean, seems the search space file is using tabs as indent. You can try to indent with spaces.

@DoveEchoing
Copy link
Author

I mean, seems the search space file is using tabs as indent. You can try to indent with spaces.

I am sorry to reply you now and misunderstand the meanning of your words. But the example ran successfully by your method.
To tell you the truth,I didn't understand your meaning at first(I modified the search space file by copying the source code,so I don't think the search space file has mistake.but.... it has...)
Like this(the file was opened by text,because I ran the example on the other computer):

yesterday's search space file
text1

after modifing
text2

and the result
result

Thanks for your reply!!!!

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

No branches or pull requests

2 participants