-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpathways_example.py
More file actions
49 lines (36 loc) · 1.19 KB
/
pathways_example.py
File metadata and controls
49 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras
import numpy as np
from keras import layers
import keras_remote
# A simple model that will be executed remotely on pathways
@keras_remote.run(accelerator="v5litepod-1", backend="pathways")
def train_simple_model():
print("Running Pathways job on JAX Backend!")
# Create a simple dataset
x = np.random.rand(1000, 10)
y = np.random.randint(0, 2, size=(1000, 1))
# A simple sequential model
model = keras.Sequential(
[
keras.Input(shape=(10,)),
layers.Dense(32, activation="relu"),
layers.Dense(16, activation="relu"),
layers.Dense(1, activation="sigmoid"),
]
)
model.compile(
optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"]
)
print("Model Architecture:")
model.summary()
# Train the model
print("\nStarting Training...")
history = model.fit(x, y, epochs=5, batch_size=32, validation_split=0.2)
print("\nTraining completed successfully on Pathways!")
return history.history
if __name__ == "__main__":
print("Submitting Pathways training job...")
result_history = train_simple_model()
print("Final validation accuracy:", result_history["val_accuracy"][-1])