diff --git a/keras/benchmarks/model_memory_profile.py b/keras/benchmarks/model_memory_profile.py index cd9971afa..927c5fdb5 100644 --- a/keras/benchmarks/model_memory_profile.py +++ b/keras/benchmarks/model_memory_profile.py @@ -37,24 +37,23 @@ FLAGS = flags.FLAGS flags.DEFINE_string("model", None, "The model to run memory profiler.") -@memory_profiler.profile -def _imdb_lstm_model(): - """LSTM model.""" - x_train = np.random.randint(0, 1999, size=(2500, 100)) - y_train = np.random.random((2500, 1)) - - # IMDB LSTM model. - model = keras.Sequential() - model.add(keras.layers.Embedding(20000, 128)) - model.add(keras.layers.LSTM(128, dropout=0.2, recurrent_dropout=0.2)) - model.add(keras.layers.Dense(1, activation="sigmoid")) - - model.compile("sgd", "mse") - # Warm up the model with one epoch. - model.fit(x_train, y_train, batch_size=512, epochs=3) - - def main(_): + @memory_profiler.profile + def _imdb_lstm_model(): + """LSTM model.""" + x_train = np.random.randint(0, 1999, size=(2500, 100)) + y_train = np.random.random((2500, 1)) + + # IMDB LSTM model. + model = keras.Sequential() + model.add(keras.layers.Embedding(20000, 128)) + model.add(keras.layers.LSTM(128, dropout=0.2, recurrent_dropout=0.2)) + model.add(keras.layers.Dense(1, activation="sigmoid")) + + model.compile("sgd", "mse") + # Warm up the model with one epoch. + model.fit(x_train, y_train, batch_size=512, epochs=3) + # Add the model for memory profile. models = { "lstm": _imdb_lstm_model, diff --git a/pip_build.py b/pip_build.py index cfd8fc6a5..1232892cd 100644 --- a/pip_build.py +++ b/pip_build.py @@ -54,7 +54,7 @@ TMP_TEST_DIRNAME = "keras_test" VERBOSE = True INIT_FILE_HEADER = """AUTOGENERATED. DO NOT EDIT.""" # These are symbols that have export issues and that we skip for now. -SYMBOLS_TO_SKIP = [] +SYMBOLS_TO_SKIP = ["layer_test"] def copy_keras_codebase(source_dir, target_dir): @@ -235,11 +235,11 @@ def generate_keras_api_files(package_directory, src_directory): root_offset=["api", "_v1", "keras"], ) # Add missing __init__ files in api dirs. - with open(os.path.join(package_directory, "api", "__init__.py"), "w") as f: + with open(os.path.join(package_directory, "api", "__init__.py"), "w"): pass - with open(os.path.join(v1_path, "__init__.py"), "w") as f: + with open(os.path.join(v1_path, "__init__.py"), "w"): pass - with open(os.path.join(v2_path, "__init__.py"), "w") as f: + with open(os.path.join(v2_path, "__init__.py"), "w"): pass