rstudio / reticulate

R Interface to Python
https://rstudio.github.io/reticulate
Apache License 2.0
1.68k stars 328 forks source link

Error: C stack usage (big number) is too close to the limit #502

Open valentas-kurauskas opened 5 years ago

valentas-kurauskas commented 5 years ago

Trying to run a custom generator function with multithreading on Ubuntu 18.04 with a simple keras (version 2.2.4) model and reticulate (version 1.10), I get random Error: C stack usage 459557818812 is too close to the limit errors and some threads crash.

def run_model(test_set, validation_set, epochs, workers, use_multiprocessing):
    model = keras.models.Sequential()
    model.add(keras.layers.Dense(units = 50, activation = "relu", input_shape = (10,100)))
    model.add(keras.layers.Dropout(rate=0.2))
    model.add(keras.layers.Dense(units=2,activation="softmax"))
    model.compile(loss = "categorical_crossentropy",optimizer = "rmsprop",metrics =["accuracy"])
    g_train = MySequenceClass(test_set)
    g_valid = MySequenceClass(validation_set)
    model.fit_generator(generator=g_train, validation_data=g_valid, epochs=epochs, workers=workers, use_multiprocessing=use_multiprocessing)

A similar closed issue #288 says it was a bug in OP's code. I am not so sure:

(I am sorry, but I do not have time at the moment to provide a complete self-contained example.)

jjallaire commented 5 years ago

You can't use multithreading with R. See the docs for the R version of fit_generator (https://www.rdocumentation.org/packages/keras/versions/2.2.4.1/topics/fit_generator). You can specify more than 1 worker, but the docs note that this is only for pure Python generator functions.

valentas-kurauskas commented 5 years ago

My generator MySequenceClass is defined in python.

jjallaire commented 5 years ago

I understand that, but the interop will still end up having some R code called on a background thread.

On Tue, May 14, 2019 at 12:22 PM Valentas notifications@github.com wrote:

My generator MySequenceClass is defined in python.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rstudio/reticulate/issues/502?email_source=notifications&email_token=AAAZPRYPMNVVKYT5FUTFB6TPVLRLXA5CNFSM4HM3QQTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVMAR7Y#issuecomment-492308735, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZPRZ4VHVFGQ4SWB7FU2DPVLRLXANCNFSM4HM3QQTA .