How to use Deepxde on Apple M1 #1100
Replies: 2 comments
-
|
This is a problem of TensorFlow for M1 chip. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, sorry for disturbing you. I have the same machine and managed to make it work by installing tensorflow-metal, which is the tensorflow version for M1 architecture. You can find further information here https://developer.apple.com/metal/tensorflow-plugin/ .
Hope this helps |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I am a student majoring in structural engineering in Korea.
I want to use deepxde in an Apple M1 chipset environment, but DeepXDE is not working properly in an M1 environment.
Compiling the model works well, but there is a problem that the M1 chipset is not recognized properly during model training.
Occasionally, when training work, but the speed is significantly slower, and most of the attached errors prevent the model training
The Adam Optimizer is slow and the L-BFGS Optimizer is not available.
How can we solve this problem?
The code used is as follows. Code for predicting deformation of the PSC beam structure. I also wrote the error code.
import tensorflow as tf
import deepxde as dde
import numpy as np
import matplotlib as plt
E = 29984 # Elastic momulus of concrete (unit: MPa)
I = 0.330 # Moment of second inertia of PSC girder (unit: m^4)
P0_true = 13.537 # Initial prestress (unit: MN)
P0 = 10.0 # Initial prestress (unit: MN)
e_max = 0.718 # Maximum eccentricity of the tendon profile (unit: m)
L = 30 # Length of PSC girder (unit: m)
phi_max_true=P0_truee_maxL2/(4EI)
phi_max=dde.Variable(P0e_maxL2/(4EI))
error_ratio=20
pridict_point=21
iteration=1
geom = dde.geometry.Interval(-1, 1)
def pde(x, y):
phi, w = y[:, 0:1], y[:,1:2]
w_xx=dde.grad.hessian(y, x, component=1)
phi0=phi_max*(x**2-1)
return [phi-phi0, w_xx-phi]
def boundary_left(x, on_boundary):
return on_boundary and np.isclose(x[0], -1)
def boundary_right(x, on_boundary):
return on_boundary and np.isclose(x[0], 1)
def boundary_center(x, on_boundary):
return on_boundary and np.isclose(x[0], 0)
bc1 = dde.DirichletBC(geom, lambda x: 0, boundary_left, component=1) # w(-1) = 0
bc2 = dde.DirichletBC(geom, lambda x: 0, boundary_right, component=1) # w(1) = 0
%Reference solution to compute the error
def true_solution_phi(x):
return phi_max_true*(x**2-1)
def true_solution_w(x):
return phi_max_true*(1/12x**4-1/2x**2+5/12)
def true_solution(x):
return phi_max_true*(x2-1), phi_max_true*(1/12*x4-1/2*x**2+5/12)
iter_phi_max=np.zeros((iteration,1))
iter_T_phi=np.zeros((iteration,pridict_point))
iter_T_w=np.zeros((iteration,pridict_point))
%for i in range (0,iteration):
%Observed data
ob_phi_x=np.array([[-1],[0],[1]])#측정지점 : n점센싱
phi_error=1+error_ratio/100*(np.random.rand(ob_phi_x.size)-0.5)2;
ob_phi_sol=true_solution_phi(ob_phi_x).T
observed_phi=dde.icbc.PointSetBC(ob_phi_x,(ob_phi_solphi_error).T, component=0)
data = dde.data.PDE(geom,
pde,
[bc1, bc2, observed_phi],
%[bc1, bc2],
num_domain = pridict_point-2,
num_boundary = 2,
solution=true_solution,
num_test = 100)
layer_size = [1] + [40]*3 + [2]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
%model.compile("adam", lr = 0.001)
model.compile("adam", lr = 0.001, external_trainable_variables=[phi_max])
variable = dde.callbacks.VariableValue([phi_max], period=1000, filename="variables.dat")
losshistory, train_state = model.train(epochs = 10000, callbacks=[variable])
%losshistory, train_state = model.train(epochs = 1000)
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
x = np.linspace(-1, 1, pridict_point)
x.shape=(x.size,1)
analytic_solution1 = true_solution_phi(x)
analytic_solution2 = true_solution_w(x)
PINN_solution = model.predict(x)
Error 1
/Users/hwangjinho/miniforge3/envs/Jinho_TF/lib/python3.8/site-packages/deepxde/nn/tensorflow_compat_v1/fnn.py:103: UserWarning:
tf.layers.denseis deprecated and will be removed in a future version. Please usetf.keras.layers.Denseinstead.return tf.layers.dense(
2023-01-02 09:59:27.778294: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:306] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2023-01-02 09:59:27.778324: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:272] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: )
Error2
2023-01-02 09:59:27.998136: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:357] MLIR V1 optimization pass is not enabled
2023-01-02 09:59:28.003618: W tensorflow/tsl/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz
2023-01-02 09:59:28.004605: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:114] Plugin optimizer for device_type GPU is enabled.
2023-01-02 09:59:28.022571: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1780] (One-time warning): Not using XLA:CPU for cluster.
If you want XLA:CPU, do one of the following:
To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a
proper command-line flag, not via TF_XLA_FLAGS).
Beta Was this translation helpful? Give feedback.
All reactions