From 573fd228e7f9f36850ad5efb2af520e9d228d065 Mon Sep 17 00:00:00 2001 From: wufei Date: Mon, 8 Apr 2024 14:22:56 +0800 Subject: [PATCH 01/22] fix doc bugs --- ppsci/geometry/pointcloud.py | 131 +++++++++++++++++++++++++++++++++-- 1 file changed, 125 insertions(+), 6 deletions(-) diff --git a/ppsci/geometry/pointcloud.py b/ppsci/geometry/pointcloud.py index cad7667a6..117789af1 100644 --- a/ppsci/geometry/pointcloud.py +++ b/ppsci/geometry/pointcloud.py @@ -102,14 +102,78 @@ def on_boundary(self, x): .any(axis=1) ) - def translate(self, translation): + def translate(self, translation: np.ndarray) -> "PointCloud": + """ + Translate the geometry by the given offset. + + Args: + translation (np.ndarray): Translation offset.The shape of translation must be the same as the shape of the interior points. + + Returns: + PointCloud: Translated point cloud. + + Examples: + >>> import ppsci + >>> import numpy as np + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",)) + >>> translation = np.array([1.0]) + >>> print(geom.translate(translation).interior) + [[1. ] + [1.5] + [2. ] + [2.5] + [3. ]] + >>> interior_points_2d = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1)), + ... "y": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom_2d = ppsci.geometry.PointCloud(interior_points_2d, ("x", "y")) + >>> translation_2d = np.array([1.0, 3.0]) + >>> print(geom_2d.translate(translation_2d).interior) + [[1. 3. ] + [1.5 3.5] + [2. 4. ] + [2.5 4.5] + [3. 5. ]] + """ for i, offset in enumerate(translation): self.interior[:, i] += offset if self.boundary: self.boundary += offset return self - def scale(self, scale): + def scale(self, scale: np.ndarray) -> "PointCloud": + """ + Scale the geometry by the given factor. + + Args: + scale (np.ndarray): Scale factor.The shape of scale must be the same as the shape of the interior points. + + Returns: + PointCloud: Scaled point cloud. + + Examples: + >>> import ppsci + >>> import numpy as np + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",)) + >>> scale = np.array([2.0]) + >>> print(geom.scale(scale).interior) + [[0.] + [1.] + [2.] + [3.] + [4.]] + >>> interior_points_2d = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1)), + ... "y": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom_2d = ppsci.geometry.PointCloud(interior_points_2d, ("x", "y")) + >>> scale_2d = np.array([2.0, 0.5]) + >>> print(geom_2d.scale(scale_2d).interior) + [[0. 0. ] + [1. 0.25] + [2. 0.5 ] + [3. 0.75] + [4. 1. ]] + """ for i, _scale in enumerate(scale): self.interior[:, i] *= _scale if self.boundary: @@ -124,7 +188,26 @@ def uniform_boundary_points(self, n: int): "PointCloud do not have 'uniform_boundary_points' method" ) - def random_boundary_points(self, n, random="pseudo"): + def random_boundary_points(self, n: int, random: str = "pseudo") -> np.ndarray: + """Randomly sample points on the boundary. + + Args: + n (int): Number of sample points. + random (str): Random method. Defaults to "pseudo". + + Returns: + np.ndarray: Randomly sampled points on the boundary.The shape of the returned array is (n, ndim). + + Examples: + >>> import ppsci + >>> import numpy as np + >>> np.random.seed(0) + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> boundary_points = {"x": np.array([0.0, 2.0], dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",), boundary_points) + >>> print(geom.random_boundary_points(1)) + [[2.]] + """ assert self.boundary is not None, ( "boundary points can't be empty when call " "'random_boundary_points' method" @@ -137,7 +220,26 @@ def random_boundary_points(self, n, random="pseudo"): np.random.choice(len(self.boundary), size=n, replace=False) ] - def random_points(self, n, random="pseudo"): + def random_points(self, n: int, random: str = "pseudo") -> np.ndarray: + """Randomly sample points in the geometry. + + Args: + n (int): Number of sample points. + random (str): Random method. Defaults to "pseudo". + + Returns: + np.ndarray: Randomly sampled points in the geometry.The shape of the returned array is (n, ndim). + + Examples: + >>> import ppsci + >>> import numpy as np + >>> np.random.seed(0) + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",)) + >>> print(geom.random_points(2)) + [[1.] + [0.]] + """ assert n <= len(self.interior), ( f"number of sample points({n}) " f"can't be more than that in points({len(self.interior)})" @@ -146,8 +248,25 @@ def random_points(self, n, random="pseudo"): np.random.choice(len(self.interior), size=n, replace=False) ] - def uniform_points(self, n: int, boundary=True): - """Compute the equi-spaced points in the geometry.""" + def uniform_points(self, n: int, boundary: bool = True) -> np.ndarray: + """Compute the equi-spaced points in the geometry. + + Args: + n (int): Number of sample points. + boundary (bool): Whether to include boundary points. Defaults to True. + + Returns: + np.ndarray: Equi-spaced points in the geometry.The shape of the returned array is (n, ndim). + + Examples: + >>> import ppsci + >>> import numpy as np + >>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))} + >>> geom = ppsci.geometry.PointCloud(interior_points, ("x",)) + >>> print(geom.uniform_points(2)) + [[0. ] + [0.5]] + """ return self.interior[:n] def union(self, other): From dfa2162632b9d88ec7296a81bf3c247d2a86b87a Mon Sep 17 00:00:00 2001 From: wufei Date: Tue, 9 Apr 2024 11:10:05 +0800 Subject: [PATCH 02/22] fix codestyle bugs --- ppsci/geometry/pointcloud.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ppsci/geometry/pointcloud.py b/ppsci/geometry/pointcloud.py index 117789af1..a5eeb10c7 100644 --- a/ppsci/geometry/pointcloud.py +++ b/ppsci/geometry/pointcloud.py @@ -222,14 +222,14 @@ def random_boundary_points(self, n: int, random: str = "pseudo") -> np.ndarray: def random_points(self, n: int, random: str = "pseudo") -> np.ndarray: """Randomly sample points in the geometry. - + Args: n (int): Number of sample points. random (str): Random method. Defaults to "pseudo". Returns: np.ndarray: Randomly sampled points in the geometry.The shape of the returned array is (n, ndim). - + Examples: >>> import ppsci >>> import numpy as np @@ -250,7 +250,7 @@ def random_points(self, n: int, random: str = "pseudo") -> np.ndarray: def uniform_points(self, n: int, boundary: bool = True) -> np.ndarray: """Compute the equi-spaced points in the geometry. - + Args: n (int): Number of sample points. boundary (bool): Whether to include boundary points. Defaults to True. From eb99d69e5b1a38839ed66caf7c9142605764c0bb Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:11:22 +0800 Subject: [PATCH 03/22] =?UTF-8?q?=E3=80=90PPSCI=20Export&Infer=20No.15-16?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/examples/ldc2d_steady.md | 12 +++ docs/zh/examples/ldc2d_unsteady.md | 12 +++ examples/ldc/conf/ldc2d_steady_Re10.yaml | 19 ++++ examples/ldc/conf/ldc2d_unsteady_Re10.yaml | 19 ++++ examples/ldc/ldc2d_steady_Re10.py | 60 ++++++++++++- examples/ldc/ldc2d_unsteady_Re10.py | 100 ++++++++++++++++++++- 6 files changed, 220 insertions(+), 2 deletions(-) diff --git a/docs/zh/examples/ldc2d_steady.md b/docs/zh/examples/ldc2d_steady.md index 037dc50bc..8a52e02a3 100644 --- a/docs/zh/examples/ldc2d_steady.md +++ b/docs/zh/examples/ldc2d_steady.md @@ -14,6 +14,18 @@ python ldc2d_steady_Re10.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_steady_Re10/ldc2d_steady_Re10_pretrained.pdparams ``` +=== "模型导出命令" + + ``` sh + python ldc2d_steady_Re10.py mode=export + ``` + +=== "模型推理命令" + + ``` sh + python ldc2d_steady_Re10.py mode=infer + ``` + | 预训练模型 | 指标 | |:--| :--| | [ldc2d_steady_Re10_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_steady_Re10/ldc2d_steady_Re10_pretrained.pdparams) | loss(Residual): 365.36164
MSE.momentum_x(Residual): 0.01435
MSE.continuity(Residual): 0.04072
MSE.momentum_y(Residual): 0.02471 | diff --git a/docs/zh/examples/ldc2d_unsteady.md b/docs/zh/examples/ldc2d_unsteady.md index 869836229..fe6a15726 100644 --- a/docs/zh/examples/ldc2d_unsteady.md +++ b/docs/zh/examples/ldc2d_unsteady.md @@ -14,6 +14,18 @@ python ldc2d_unsteady_Re10.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_unsteady_Re10/ldc2d_unsteady_Re10_pretrained.pdparams ``` +=== "模型导出命令" + + ``` sh + python ldc2d_unsteady_Re10.py mode=export + ``` + +=== "模型推理命令" + + ``` sh + python ldc2d_unsteady_Re10.py mode=infer + ``` + | 预训练模型 | 指标 | |:--| :--| | [ldc2d_unsteady_Re10_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_unsteady_Re10/ldc2d_unsteady_Re10_pretrained.pdparams) | loss(Residual): 155652.67530
MSE.momentum_x(Residual): 6.78030
MSE.continuity(Residual): 0.16590
MSE.momentum_y(Residual): 12.05981 | diff --git a/examples/ldc/conf/ldc2d_steady_Re10.yaml b/examples/ldc/conf/ldc2d_steady_Re10.yaml index 079d1e442..330089927 100644 --- a/examples/ldc/conf/ldc2d_steady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_steady_Re10.yaml @@ -22,6 +22,7 @@ hydra: mode: train # running mode: train/eval seed: 42 output_dir: ${hydra:run.dir} +log_freq: 20 # set working condition NU: 0.01 @@ -55,3 +56,21 @@ EVAL: pretrained_model_path: null batch_size: residual_validator: 8192 + +# inference settings +INFER: + pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_steady_Re10/ldc2d_steady_Re10_pretrained.pdparams + export_path: ./inference/ldc2d_steady_Re10 + pdmodel_path: ${INFER.export_path}.pdmodel + pdpiparams_path: ${INFER.export_path}.pdiparams + onnx_path: ${INFER.export_path}.onnx + device: gpu + engine: native + precision: fp32 + ir_optim: true + min_subgraph_size: 5 + gpu_mem: 2000 + gpu_id: 0 + max_batch_size: 8192 + num_cpu_threads: 10 + batch_size: 8192 \ No newline at end of file diff --git a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml index 0414836af..4f597bd61 100644 --- a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml @@ -22,6 +22,7 @@ hydra: mode: train # running mode: train/eval seed: 42 output_dir: ${hydra:run.dir} +log_freq: 20 # set working condition NU: 0.01 @@ -56,3 +57,21 @@ EVAL: pretrained_model_path: null batch_size: residual_validator: 8192 + +# inference settings +INFER: + pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/ldc2d_unsteady_Re10/ldc2d_unsteady_Re10_pretrained.pdparams + export_path: ./inference/ldc2d_unsteady_Re10 + pdmodel_path: ${INFER.export_path}.pdmodel + pdiparams_path: ${INFER.export_path}.pdiparams + onnx_path: ${INFER.export_path}.onnx + device: gpu + engine: native + precision: fp32 + ir_optim: true + min_subgraph_size: 5 + gpu_mem: 2000 + gpu_id: 0 + max_batch_size: 8192 + num_cpu_threads: 10 + batch_size: 8192 \ No newline at end of file diff --git a/examples/ldc/ldc2d_steady_Re10.py b/examples/ldc/ldc2d_steady_Re10.py index 37cf32541..5e4cda2c7 100644 --- a/examples/ldc/ldc2d_steady_Re10.py +++ b/examples/ldc/ldc2d_steady_Re10.py @@ -234,6 +234,60 @@ def evaluate(cfg: DictConfig): solver.visualize() +def export(cfg: DictConfig): + # set model + model = ppsci.arch.MLP(**cfg.MODEL) + + # initialize solver + solver = ppsci.solver.Solver( + model, + pretrained_model_path=cfg.INFER.pretrained_model_path, + ) + # export model + from paddle.static import InputSpec + + input_spec = [ + {key: InputSpec([None, 1], "float32", name=key) for key in model.input_keys}, + ] + solver.export(input_spec, cfg.INFER.export_path) + + +def inference(cfg: DictConfig): + from deploy.python_infer import pinn_predictor + + predictor = pinn_predictor.PINNPredictor(cfg) + + # set geometry + geom = {"rect": ppsci.geometry.Rectangle((-0.05, -0.05), (0.05, 0.05))} + # manually collate input data for inference + NPOINT_PDE = 99**2 + NPOINT_TOP = 101 + NPOINT_BOTTOM = 101 + NPOINT_LEFT = 99 + NPOINT_RIGHT = 99 + NPOINT_BC = NPOINT_TOP + NPOINT_BOTTOM + NPOINT_LEFT + NPOINT_RIGHT + input_dict = geom["rect"].sample_interior(NPOINT_PDE + NPOINT_BC, evenly=True) + output_dict = predictor.predict( + {key: input_dict[key] for key in cfg.MODEL.input_keys}, cfg.INFER.batch_size + ) + + # mapping data to cfg.INFER.output_keys + output_dict = { + store_key:output_dict[infer_key] + for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) + } + + ppsci.visualize.save_vtu_from_dict( + "./ldc2d_steady_Re10.vtu", + {**input_dict, **output_dict}, + input_dict.keys(), + cfg.MODEL.output_keys, + ) + + + + + @hydra.main( version_base=None, config_path="./conf", config_name="ldc2d_steady_Re10.yaml" ) @@ -242,8 +296,12 @@ def main(cfg: DictConfig): train(cfg) elif cfg.mode == "eval": evaluate(cfg) + elif cfg.mode == "export": + export(cfg) + elif cfg.mode == "infer": + inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'") + raise ValueError(f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'") if __name__ == "__main__": diff --git a/examples/ldc/ldc2d_unsteady_Re10.py b/examples/ldc/ldc2d_unsteady_Re10.py index 3ed4ba705..a9fb08b48 100644 --- a/examples/ldc/ldc2d_unsteady_Re10.py +++ b/examples/ldc/ldc2d_unsteady_Re10.py @@ -308,6 +308,100 @@ def evaluate(cfg: DictConfig): solver.visualize() +def export(cfg: DictConfig): + # set model + model = ppsci.arch.MLP(**cfg.MODEL) + + # initialize solver + solver = ppsci.solver.Solver( + model, + pretrained_model_path=cfg.INFER.pretrained_model_path, + ) + # export model + from paddle.static import InputSpec + + input_spec = [ + {key: InputSpec([None, 1], "float32", name=key) for key in model.input_keys}, + ] + solver.export(input_spec, cfg.INFER.export_path) + + +def inference(cfg: DictConfig): + from deploy.python_infer import pinn_predictor + + predictor = pinn_predictor.PINNPredictor(cfg) + + # set timestamps(including initial t0) + timestamps = np.linspace(0.0, 1.5, cfg.NTIME_ALL, endpoint=True) + # set time-geometry + geom = { + "time_rect": ppsci.geometry.TimeXGeometry( + ppsci.geometry.TimeDomain(0.0, 1.5, timestamps=timestamps), + ppsci.geometry.Rectangle((-0.05, -0.05), (0.05, 0.05)), + ) + } + # manually collate input data for inference + NPOINT_PDE = 99**2 + NPOINT_TOP = 101 + NPOINT_DOWN = 101 + NPOINT_LEFT = 99 + NPOINT_RIGHT = 99 + NPOINT_IC = 99**2 + NTIME_PDE = cfg.NTIME_ALL - 1 + NPOINT_BC = NPOINT_TOP + NPOINT_DOWN + NPOINT_LEFT + NPOINT_RIGHT + input_dict = geom["time_rect"].sample_initial_interior( + (NPOINT_IC + NPOINT_BC), evenly=True + ) + del input_dict["sdf"] + input_pde_dict = geom["time_rect"].sample_interior( + (NPOINT_PDE + NPOINT_BC) * NTIME_PDE, evenly=True + ) + # (interior+boundary) x all timestamps + for t in range(NTIME_PDE): + for key in geom["time_rect"].dim_keys: + input_dict[key] = np.concatenate( + ( + input_dict[key], + input_pde_dict[key][ + t + * (NPOINT_PDE + NPOINT_BC) : (t + 1) + * (NPOINT_PDE + NPOINT_BC) + ], + ) + ) + output_dict = predictor.predict( + {key: input_dict[key] for key in cfg.MODEL.input_keys}, cfg.INFER.batch_size + ) + + # mapping data to cfg.INFER.output_keys + output_dict = { + store_key: output_dict[infer_key] + for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) + } + + unique_t_values = np.unique(input_dict['t']) + segmented_input_dict = {} + segmented_output_dict = {} + for idx, t_value in enumerate(unique_t_values): + # Find the indices corresponding to the current t value + indices = np.where(input_dict['t'] == t_value)[0] + # Extract the corresponding x and y values based on the indices + x_values = input_dict['x'][indices] + y_values = input_dict['y'][indices] + u_values = output_dict['u'][indices] + v_values = output_dict['v'][indices] + p_values = output_dict['p'][indices] + # Construct segmented dictionaries + segmented_input_dict = {'x': x_values, 'y': y_values} + segmented_output_dict = {'u': u_values, 'v': v_values, 'p': p_values} + ppsci.visualize.save_vtu_from_dict( + "./ldc2d_unsteady_Re10_pred_"+ str(idx) + ".vtu", + {**segmented_input_dict, **segmented_output_dict}, + input_dict.keys(), + cfg.MODEL.output_keys, + ) + + @hydra.main( version_base=None, config_path="./conf", config_name="ldc2d_unsteady_Re10.yaml" ) @@ -316,8 +410,12 @@ def main(cfg: DictConfig): train(cfg) elif cfg.mode == "eval": evaluate(cfg) + elif cfg.mode == "export": + export(cfg) + elif cfg.mode == "infer": + inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'") + raise ValueError(f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'") if __name__ == "__main__": From 2986349051019ed7848916e22098de75a8bbc90a Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:21:00 +0800 Subject: [PATCH 04/22] =?UTF-8?q?fix=20codestyle=20bug=20for=20PPSCI=20Exp?= =?UTF-8?q?ort&Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/ldc2d_steady_Re10.py | 6 ++++-- examples/ldc/ldc2d_unsteady_Re10.py | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/examples/ldc/ldc2d_steady_Re10.py b/examples/ldc/ldc2d_steady_Re10.py index 5e4cda2c7..9cb4af2ab 100644 --- a/examples/ldc/ldc2d_steady_Re10.py +++ b/examples/ldc/ldc2d_steady_Re10.py @@ -273,7 +273,7 @@ def inference(cfg: DictConfig): # mapping data to cfg.INFER.output_keys output_dict = { - store_key:output_dict[infer_key] + store_key: output_dict[infer_key] for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) } @@ -301,7 +301,9 @@ def main(cfg: DictConfig): elif cfg.mode == "infer": inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'") + raise ValueError( + f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'" + ) if __name__ == "__main__": diff --git a/examples/ldc/ldc2d_unsteady_Re10.py b/examples/ldc/ldc2d_unsteady_Re10.py index a9fb08b48..40cbca474 100644 --- a/examples/ldc/ldc2d_unsteady_Re10.py +++ b/examples/ldc/ldc2d_unsteady_Re10.py @@ -352,7 +352,6 @@ def inference(cfg: DictConfig): input_dict = geom["time_rect"].sample_initial_interior( (NPOINT_IC + NPOINT_BC), evenly=True ) - del input_dict["sdf"] input_pde_dict = geom["time_rect"].sample_interior( (NPOINT_PDE + NPOINT_BC) * NTIME_PDE, evenly=True ) @@ -379,23 +378,23 @@ def inference(cfg: DictConfig): for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) } - unique_t_values = np.unique(input_dict['t']) + unique_t_values = np.unique(input_dict["t"]) segmented_input_dict = {} segmented_output_dict = {} for idx, t_value in enumerate(unique_t_values): # Find the indices corresponding to the current t value - indices = np.where(input_dict['t'] == t_value)[0] + indices = np.where(input_dict["t"] == t_value)[0] # Extract the corresponding x and y values based on the indices - x_values = input_dict['x'][indices] - y_values = input_dict['y'][indices] - u_values = output_dict['u'][indices] - v_values = output_dict['v'][indices] - p_values = output_dict['p'][indices] + x_values = input_dict["x"][indices] + y_values = input_dict["y"][indices] + u_values = output_dict["u"][indices] + v_values = output_dict["v"][indices] + p_values = output_dict["p"][indices] # Construct segmented dictionaries - segmented_input_dict = {'x': x_values, 'y': y_values} - segmented_output_dict = {'u': u_values, 'v': v_values, 'p': p_values} + segmented_input_dict = {"x": x_values, "y": y_values} + segmented_output_dict = {"u": u_values, "v": v_values, "p": p_values} ppsci.visualize.save_vtu_from_dict( - "./ldc2d_unsteady_Re10_pred_"+ str(idx) + ".vtu", + "./ldc2d_unsteady_Re10_pred_" + str(idx) + ".vtu", {**segmented_input_dict, **segmented_output_dict}, input_dict.keys(), cfg.MODEL.output_keys, @@ -415,7 +414,9 @@ def main(cfg: DictConfig): elif cfg.mode == "infer": inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'") + raise ValueError( + f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'" + ) if __name__ == "__main__": From cfab6002d51b6595ebdd7884ec9fa8e1c2625dfd Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:24:51 +0800 Subject: [PATCH 05/22] =?UTF-8?q?fix=20codestyle=20bugs=20for=20=E3=80=90P?= =?UTF-8?q?PSCI=20Export&Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/ldc2d_steady_Re10.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/ldc/ldc2d_steady_Re10.py b/examples/ldc/ldc2d_steady_Re10.py index 9cb4af2ab..3c6507932 100644 --- a/examples/ldc/ldc2d_steady_Re10.py +++ b/examples/ldc/ldc2d_steady_Re10.py @@ -284,9 +284,6 @@ def inference(cfg: DictConfig): cfg.MODEL.output_keys, ) - - - @hydra.main( version_base=None, config_path="./conf", config_name="ldc2d_steady_Re10.yaml" From cf0c33f2a9137638c427c9cd99cb9287bcab0a8f Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:29:48 +0800 Subject: [PATCH 06/22] =?UTF-8?q?fix=20codestyle=20bugs=20for=20=E3=80=90P?= =?UTF-8?q?PSCI=20Export&Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/conf/ldc2d_steady_Re10.yaml | 3 ++- examples/ldc/conf/ldc2d_unsteady_Re10.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/ldc/conf/ldc2d_steady_Re10.yaml b/examples/ldc/conf/ldc2d_steady_Re10.yaml index 330089927..21dc93e9b 100644 --- a/examples/ldc/conf/ldc2d_steady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_steady_Re10.yaml @@ -73,4 +73,5 @@ INFER: gpu_id: 0 max_batch_size: 8192 num_cpu_threads: 10 - batch_size: 8192 \ No newline at end of file + batch_size: 8192 + \ No newline at end of file diff --git a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml index 4f597bd61..fe744b5a7 100644 --- a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml @@ -74,4 +74,5 @@ INFER: gpu_id: 0 max_batch_size: 8192 num_cpu_threads: 10 - batch_size: 8192 \ No newline at end of file + batch_size: 8192 + \ No newline at end of file From 7f8bfb2f62e098505474b29b8074231dd5d22009 Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 2 May 2024 16:32:13 +0800 Subject: [PATCH 07/22] =?UTF-8?q?fix=20codestyle=20bugs=20for=20=E3=80=90P?= =?UTF-8?q?PSCI=20Export&Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/conf/ldc2d_steady_Re10.yaml | 1 - examples/ldc/conf/ldc2d_unsteady_Re10.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/examples/ldc/conf/ldc2d_steady_Re10.yaml b/examples/ldc/conf/ldc2d_steady_Re10.yaml index 21dc93e9b..cc4c62c4e 100644 --- a/examples/ldc/conf/ldc2d_steady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_steady_Re10.yaml @@ -74,4 +74,3 @@ INFER: max_batch_size: 8192 num_cpu_threads: 10 batch_size: 8192 - \ No newline at end of file diff --git a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml index fe744b5a7..e03441980 100644 --- a/examples/ldc/conf/ldc2d_unsteady_Re10.yaml +++ b/examples/ldc/conf/ldc2d_unsteady_Re10.yaml @@ -75,4 +75,3 @@ INFER: max_batch_size: 8192 num_cpu_threads: 10 batch_size: 8192 - \ No newline at end of file From ddee33e7123df89ca9a8cc99a750fabbea627dbc Mon Sep 17 00:00:00 2001 From: wufei Date: Mon, 6 May 2024 16:46:33 +0800 Subject: [PATCH 08/22] =?UTF-8?q?fix=20bugs=20for=20=E3=80=90PPSCI=20Expor?= =?UTF-8?q?t&Infer=20No.15-16=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ldc/ldc2d_unsteady_Re10.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/examples/ldc/ldc2d_unsteady_Re10.py b/examples/ldc/ldc2d_unsteady_Re10.py index 40cbca474..bed7690ae 100644 --- a/examples/ldc/ldc2d_unsteady_Re10.py +++ b/examples/ldc/ldc2d_unsteady_Re10.py @@ -378,27 +378,13 @@ def inference(cfg: DictConfig): for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) } - unique_t_values = np.unique(input_dict["t"]) - segmented_input_dict = {} - segmented_output_dict = {} - for idx, t_value in enumerate(unique_t_values): - # Find the indices corresponding to the current t value - indices = np.where(input_dict["t"] == t_value)[0] - # Extract the corresponding x and y values based on the indices - x_values = input_dict["x"][indices] - y_values = input_dict["y"][indices] - u_values = output_dict["u"][indices] - v_values = output_dict["v"][indices] - p_values = output_dict["p"][indices] - # Construct segmented dictionaries - segmented_input_dict = {"x": x_values, "y": y_values} - segmented_output_dict = {"u": u_values, "v": v_values, "p": p_values} - ppsci.visualize.save_vtu_from_dict( - "./ldc2d_unsteady_Re10_pred_" + str(idx) + ".vtu", - {**segmented_input_dict, **segmented_output_dict}, - input_dict.keys(), - cfg.MODEL.output_keys, - ) + ppsci.visualize.save_vtu_from_dict( + "./ldc2d_unsteady_Re10_pred.vtu", + {**input_dict, **output_dict}, + input_dict.keys(), + cfg.MODEL.output_keys, + cfg.NTIME_ALL + ) @hydra.main( From dfb36490122887b6cf4cc3a59880c8348614461d Mon Sep 17 00:00:00 2001 From: wufei Date: Mon, 6 May 2024 16:52:10 +0800 Subject: [PATCH 09/22] fix codestyle bugs --- examples/ldc/ldc2d_unsteady_Re10.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ldc/ldc2d_unsteady_Re10.py b/examples/ldc/ldc2d_unsteady_Re10.py index bed7690ae..aeb88868c 100644 --- a/examples/ldc/ldc2d_unsteady_Re10.py +++ b/examples/ldc/ldc2d_unsteady_Re10.py @@ -383,7 +383,7 @@ def inference(cfg: DictConfig): {**input_dict, **output_dict}, input_dict.keys(), cfg.MODEL.output_keys, - cfg.NTIME_ALL + cfg.NTIME_ALL, ) From ae4b62723b2e33fc0df1b8124e7fe8d2be135ad3 Mon Sep 17 00:00:00 2001 From: wufei Date: Wed, 8 May 2024 15:50:12 +0800 Subject: [PATCH 10/22] =?UTF-8?q?=E3=80=90PPSCI=20Export&Infer=20No.11-12?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/examples/cylinder2d_unsteady.md | 18 +++++ .../cylinder2d_unsteady_transformer_physx.md | 17 ++++ .../conf/cylinder2d_unsteady_Re100.yaml | 18 +++++ .../2d_unsteady/cylinder2d_unsteady_Re100.py | 61 +++++++++++++- .../transformer_physx/conf/transformer.yaml | 17 ++++ .../transformer_physx/train_transformer.py | 79 ++++++++++++++++++- 6 files changed, 208 insertions(+), 2 deletions(-) diff --git a/docs/zh/examples/cylinder2d_unsteady.md b/docs/zh/examples/cylinder2d_unsteady.md index 9df6966f6..33e35b8de 100644 --- a/docs/zh/examples/cylinder2d_unsteady.md +++ b/docs/zh/examples/cylinder2d_unsteady.md @@ -26,6 +26,24 @@ python cylinder2d_unsteady_Re100.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/cylinder2d_unsteady_Re100/cylinder2d_unsteady_Re100_pretrained.pdparams ``` + === "模型导出命令" + + ``` sh + python cylinder2d_unsteady_Re100.py mode=export + ``` + +=== "模型推理命令" + + ``` sh + # linux + wget -nc https://paddle-org.bj.bcebos.com/paddlescience/datasets/cylinder2d_unsteady_Re100/cylinder2d_unsteady_Re100_dataset.tar + # windows + # curl https://paddle-org.bj.bcebos.com/paddlescience/datasets/cylinder2d_unsteady_Re100/cylinder2d_unsteady_Re100_dataset.tar --output cylinder2d_unsteady_Re100_dataset.tar + # unzip it + tar -xvf cylinder2d_unsteady_Re100_dataset.tar + python cylinder2d_unsteady_Re100.py mode=infer + ``` + | 预训练模型 | 指标 | |:--| :--| | [cylinder2d_unsteady_Re100_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/cylinder2d_unsteady_Re100/cylinder2d_unsteady_Re100_pretrained.pdparams) | loss(Residual): 0.00398
MSE.continuity(Residual): 0.00126
MSE.momentum_x(Residual): 0.00151
MSE.momentum_y(Residual): 0.00120 | diff --git a/docs/zh/examples/cylinder2d_unsteady_transformer_physx.md b/docs/zh/examples/cylinder2d_unsteady_transformer_physx.md index b241bb2ec..721fa1caf 100644 --- a/docs/zh/examples/cylinder2d_unsteady_transformer_physx.md +++ b/docs/zh/examples/cylinder2d_unsteady_transformer_physx.md @@ -27,6 +27,23 @@ python train_enn.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/cylinder/cylinder_pretrained.pdparams python train_transformer.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/cylinder/cylinder_transformer_pretrained.pdparams EMBEDDING_MODEL_PATH=https://paddle-org.bj.bcebos.com/paddlescience/models/cylinder/cylinder_pretrained.pdparams ``` + === "模型导出命令" + + ``` sh + python train_transformer.py mode=export EMBEDDING_MODEL_PATH=https://paddle-org.bj.bcebos.com/paddlescience/models/cylinder/cylinder_pretrained.pdparams + ``` + +=== "模型推理命令" + + ``` sh + # linux + wget -nc https://paddle-org.bj.bcebos.com/paddlescience/datasets/transformer_physx/cylinder_training.hdf5 -P ./datasets/ + wget -nc https://paddle-org.bj.bcebos.com/paddlescience/datasets/transformer_physx/cylinder_valid.hdf5 -P ./datasets/ + # windows + # curl https://paddle-org.bj.bcebos.com/paddlescience/datasets/transformer_physx/cylinder_training.hdf5 --output ./datasets/cylinder_training.hdf5 + # curl https://paddle-org.bj.bcebos.com/paddlescience/datasets/transformer_physx/cylinder_valid.hdf5 --output ./datasets/cylinder_valid.hdf5 + python train_transformer.py mode=infer + ``` | 模型 | MSE | | :-- | :-- | diff --git a/examples/cylinder/2d_unsteady/conf/cylinder2d_unsteady_Re100.yaml b/examples/cylinder/2d_unsteady/conf/cylinder2d_unsteady_Re100.yaml index dc96d3c98..10d4a964c 100644 --- a/examples/cylinder/2d_unsteady/conf/cylinder2d_unsteady_Re100.yaml +++ b/examples/cylinder/2d_unsteady/conf/cylinder2d_unsteady_Re100.yaml @@ -70,3 +70,21 @@ TRAIN: EVAL: batch_size: 10240 pretrained_model_path: null + +# inference settings +INFER: + pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/cylinder2d_unsteady_Re100/cylinder2d_unsteady_Re100_pretrained.pdparams + export_path: ./inference/cylinder2d_unsteady_Re100 + pdmodel_path: ${INFER.export_path}.pdmodel + pdiparams_path: ${INFER.export_path}.pdiparams + onnx_path: ${INFER.export_path}.onnx + device: gpu + engine: native + precision: fp32 + ir_optim: true + min_subgraph_size: 5 + gpu_mem: 2000 + gpu_id: 0 + max_batch_size: 10240 + num_cpu_threads: 10 + batch_size: 10240 diff --git a/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py b/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py index 2f9d02e4b..379646090 100644 --- a/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py +++ b/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py @@ -311,6 +311,59 @@ def evaluate(cfg: DictConfig): solver.visualize() +def export(cfg: DictConfig): + # set model + model = ppsci.arch.MLP(**cfg.MODEL) + + # initialize solver + solver = ppsci.solver.Solver( + model, + pretrained_model_path=cfg.INFER.pretrained_model_path, + ) + # export model + from paddle.static import InputSpec + + input_spec = [ + {key: InputSpec([None, 1], "float32", name=key) for key in model.input_keys}, + ] + solver.export(input_spec, cfg.INFER.export_path) + + +def inference(cfg: DictConfig): + from deploy.python_infer import pinn_predictor + + predictor = pinn_predictor.PINNPredictor(cfg) + # set time-geometry + geom = { + "time_rect_eval": ppsci.geometry.PointCloud( + reader.load_csv_file( + cfg.DOMAIN_EVAL_PATH, + ("t", "x", "y"), + ), + ("t", "x", "y"), + ), + } + NPOINT_EVAL = ( + cfg.NPOINT_PDE + cfg.NPOINT_INLET_CYLINDER + cfg.NPOINT_OUTLET + ) * cfg.NUM_TIMESTAMPS + input_dict = geom["time_rect_eval"].sample_interior(NPOINT_EVAL, evenly=True) + output_dict = predictor.predict(input_dict, cfg.INFER.batch_size) + + # mapping data to cfg.INFER.output_keys + output_dict = { + store_key: output_dict[infer_key] + for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) + } + + ppsci.visualize.save_vtu_from_dict( + "./cylinder2d_unsteady_Re100_pred.vtu", + {**input_dict, **output_dict}, + input_dict.keys(), + cfg.MODEL.output_keys, + cfg.NUM_TIMESTAMPS, + ) + + @hydra.main( version_base=None, config_path="./conf", @@ -321,8 +374,14 @@ def main(cfg: DictConfig): train(cfg) elif cfg.mode == "eval": evaluate(cfg) + elif cfg.mode == "export": + export(cfg) + elif cfg.mode == "infer": + inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'") + raise ValueError( + f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'" + ) if __name__ == "__main__": diff --git a/examples/cylinder/2d_unsteady/transformer_physx/conf/transformer.yaml b/examples/cylinder/2d_unsteady/transformer_physx/conf/transformer.yaml index 7fff3caa7..cc7523c8a 100644 --- a/examples/cylinder/2d_unsteady/transformer_physx/conf/transformer.yaml +++ b/examples/cylinder/2d_unsteady/transformer_physx/conf/transformer.yaml @@ -63,3 +63,20 @@ TRAIN: EVAL: batch_size: 16 pretrained_model_path: null + +INFER: + pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/cylinder/cylinder_transformer_pretrained.pdparams + export_path: ./inference/cylinder_transformer + pdmodel_path: ${INFER.export_path}.pdmodel + pdiparams_path: ${INFER.export_path}.pdiparams + device: gpu + engine: native + precision: fp32 + onnx_path: ${INFER.export_path}.onnx + ir_optim: false + min_subgraph_size: 10 + gpu_mem: 4000 + gpu_id: 0 + max_batch_size: 16 + num_cpu_threads: 4 + batch_size: 16 diff --git a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py index aadfd4ce5..f1f2e8316 100644 --- a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py +++ b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py @@ -262,14 +262,91 @@ def evaluate(cfg: DictConfig): solver.visualize() +def export(cfg: DictConfig): + # set model + embedding_model = build_embedding_model(cfg.EMBEDDING_MODEL_PATH) + model_cfg = { + **cfg.MODEL, + "embedding_model": embedding_model, + "input_keys": ["states"], + "output_keys": ["pred_states"], + } + model = ppsci.arch.PhysformerGPT2(**model_cfg) + + # initialize solver + solver = ppsci.solver.Solver( + model, + pretrained_model_path=cfg.INFER.pretrained_model_path, + ) + # export model + from paddle.static import InputSpec + + input_spec = [ + { + key: InputSpec([None, 255, 128], "float32", name=key) + for key in model.input_keys + }, + ] + + solver.export(input_spec, cfg.INFER.export_path) + + +def inference(cfg: DictConfig): + from deploy.python_infer import pinn_predictor + + predictor = pinn_predictor.PINNPredictor(cfg) + + dataset_cfg = { + "name": "CylinderDataset", + "file_path": cfg.VALID_FILE_PATH, + "input_keys": cfg.MODEL.input_keys, + "label_keys": cfg.MODEL.output_keys, + "block_size": cfg.VALID_BLOCK_SIZE, + "stride": 1024, + } + + dataset = ppsci.data.dataset.build_dataset(dataset_cfg) + + input_dict = { + "states": dataset.data[: cfg.VIS_DATA_NUMS, :-1], + } + + output_dict = predictor.predict(input_dict, cfg.INFER.batch_size) + + # mapping data to cfg.INFER.output_keys + output_keys = ["pred_states"] + output_dict = { + store_key: output_dict[infer_key] + for store_key, infer_key in zip(output_keys, output_dict.keys()) + } + + input_dict = { + "states": dataset.data[: cfg.VIS_DATA_NUMS, 1:], + } + + data_dict = {**input_dict, **output_dict} + for i in range(cfg.VIS_DATA_NUMS): + ppsci.visualize.save_plot_from_3d_dict( + f"./cylinder_transformer_pred_{i}", + {key: value[i] for key, value in data_dict.items()}, + ("states", "pred_states"), + ) + + @hydra.main(version_base=None, config_path="./conf", config_name="transformer.yaml") def main(cfg: DictConfig): if cfg.mode == "train": train(cfg) elif cfg.mode == "eval": evaluate(cfg) + elif cfg.mode == "export": + export(cfg) + elif cfg.mode == "infer": + inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'") + raise ValueError( + f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'" + ) if __name__ == "__main__": From 20ba5f77742625c270fc268d1fa95ed9c5c3ebc5 Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 9 May 2024 17:28:00 +0800 Subject: [PATCH 11/22] change predictor --- .../transformer_physx/train_transformer.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py index f1f2e8316..8f619607f 100644 --- a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py +++ b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py @@ -292,9 +292,22 @@ def export(cfg: DictConfig): def inference(cfg: DictConfig): - from deploy.python_infer import pinn_predictor - - predictor = pinn_predictor.PINNPredictor(cfg) + from deploy.python_infer import base + + predictor = base.Predictor( + cfg.INFER.pdmodel_path, + cfg.INFER.pdiparams_path, + device=cfg.INFER.device, + engine=cfg.INFER.engine, + precision=cfg.INFER.precision, + onnx_path=cfg.INFER.onnx_path, + ir_optim=cfg.INFER.ir_optim, + min_subgraph_size=cfg.INFER.min_subgraph_size, + gpu_mem=cfg.INFER.gpu_mem, + gpu_id=cfg.INFER.gpu_id, + max_batch_size=cfg.INFER.max_batch_size, + num_cpu_threads=cfg.INFER.num_cpu_threads, + ) dataset_cfg = { "name": "CylinderDataset", From b20be86596ec82fd5c648abb78050a5899938e6e Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 9 May 2024 17:45:31 +0800 Subject: [PATCH 12/22] fix bugs in change predictor --- examples/bubble/bubble.py | 104 +++++++++++++++++- examples/bubble/conf/bubble.yaml | 18 +++ .../transformer_physx/train_transformer.py | 2 +- 3 files changed, 122 insertions(+), 2 deletions(-) diff --git a/examples/bubble/bubble.py b/examples/bubble/bubble.py index 86ce46a2a..6806e91a4 100644 --- a/examples/bubble/bubble.py +++ b/examples/bubble/bubble.py @@ -403,14 +403,116 @@ def transform_out(in_, out): ) +def export(cfg: DictConfig): + # set model + model_psi = ppsci.arch.MLP(**cfg.MODEL.psi_net) + model_p = ppsci.arch.MLP(**cfg.MODEL.p_net) + model_phil = ppsci.arch.MLP(**cfg.MODEL.phil_net) + + # transform + def transform_out(in_, out): + psi_y = out["psi"] + y = in_["y"] + x = in_["x"] + u = jacobian(psi_y, y, create_graph=False) + v = -jacobian(psi_y, x, create_graph=False) + return {"u": u, "v": v} + + # register transform + model_psi.register_output_transform(transform_out) + model_list = ppsci.arch.ModelList((model_psi, model_p, model_phil)) + + # initialize solver + solver = ppsci.solver.Solver( + model_list, + pretrained_model_path=cfg.INFER.pretrained_model_path, + ) + # export model + from paddle.static import InputSpec + input_spec = [ + InputSpec(shape=[None, 1], dtype="float32", name="t"), + InputSpec(shape=[None, 1], dtype="float32", name="x"), + InputSpec(shape=[None, 1], dtype="float32", name="y"), + ] + solver.export(input_spec, cfg.INFER.export_path) + + +def inference(cfg: DictConfig): + # load Data + data = scipy.io.loadmat(cfg.DATA_PATH) + # normalize data + p_max = data["p"].max(axis=0) + p_min = data["p"].min(axis=0) + u_max = data["u"].max(axis=0) + u_min = data["u"].min(axis=0) + v_max = data["v"].max(axis=0) + v_min = data["v"].min(axis=0) + + from deploy.python_infer import pinn_predictor + + predictor = pinn_predictor.PINNPredictor(cfg) + # set time-geometry + timestamps = np.linspace(0, 126, 127, endpoint=True) + geom = { + "time_rect_visu": ppsci.geometry.TimeXGeometry( + ppsci.geometry.TimeDomain(1, 126, timestamps=timestamps), + ppsci.geometry.Rectangle((0, 0), (15, 5)), + ), + } + NTIME_ALL = len(timestamps) + NPOINT_PDE, NTIME_PDE = 300 * 100, NTIME_ALL - 1 + input_dict = geom["time_rect_visu"].sample_interior( + NPOINT_PDE * NTIME_PDE, evenly=True + ) + output_dict = predictor.predict(input_dict, cfg.INFER.batch_size) + + # mapping data to cfg.INFER.output_keys + output_dict = { + store_key: output_dict[infer_key] + for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) + } + + # inverse normalization + p_pred = output_dict["p"].reshape([NTIME_PDE, NPOINT_PDE]).T + u_pred = output_dict["u"].reshape([NTIME_PDE, NPOINT_PDE]).T + v_pred = output_dict["v"].reshape([NTIME_PDE, NPOINT_PDE]).T + pred = { + "p": (p_pred * (p_max - p_min) + p_min).T.reshape([-1, 1]), + "u": (u_pred * (u_max - u_min) + u_min).T.reshape([-1, 1]), + "v": (v_pred * (v_max - v_min) + v_min).T.reshape([-1, 1]), + "phil": output_dict["phil"], + } + ppsci.visualize.save_vtu_from_dict( + osp.join(cfg.output_dir, "visual/result.vtu"), + { + "t": input_dict["t"], + "x": input_dict["x"], + "y": input_dict["y"], + "u": pred["u"], + "v": pred["v"], + "p": pred["p"], + "phil": pred["phil"], + }, + ("t", "x", "y"), + ("u", "v", "p", "phil"), + NTIME_PDE, + ) + + @hydra.main(version_base=None, config_path="./conf", config_name="bubble.yaml") def main(cfg: DictConfig): if cfg.mode == "train": train(cfg) elif cfg.mode == "eval": evaluate(cfg) + elif cfg.mode == "export": + export(cfg) + elif cfg.mode == "infer": + inference(cfg) else: - raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'") + raise ValueError( + f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'" + ) if __name__ == "__main__": diff --git a/examples/bubble/conf/bubble.yaml b/examples/bubble/conf/bubble.yaml index 40262276a..dcceff01a 100644 --- a/examples/bubble/conf/bubble.yaml +++ b/examples/bubble/conf/bubble.yaml @@ -65,3 +65,21 @@ TRAIN: EVAL: pretrained_model_path: null eval_with_no_grad: true + +# inference settings +INFER: + pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/bubble/bubble_pretrained.pdparams + export_path: ./inference/bubble + pdmodel_path: ${INFER.export_path}.pdmodel + pdiparams_path: ${INFER.export_path}.pdiparams + onnx_path: ${INFER.export_path}.onnx + device: gpu + engine: native + precision: fp32 + ir_optim: true + min_subgraph_size: 5 + gpu_mem: 2000 + gpu_id: 0 + max_batch_size: 1024 + num_cpu_threads: 10 + batch_size: 1024 diff --git a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py index 8f619607f..0b767f024 100644 --- a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py +++ b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py @@ -324,7 +324,7 @@ def inference(cfg: DictConfig): "states": dataset.data[: cfg.VIS_DATA_NUMS, :-1], } - output_dict = predictor.predict(input_dict, cfg.INFER.batch_size) + output_dict = predictor.predict(input_dict) # mapping data to cfg.INFER.output_keys output_keys = ["pred_states"] From 800cf774afc8525a64f5d8c851901127232585b3 Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 9 May 2024 17:54:16 +0800 Subject: [PATCH 13/22] cancel extra doc commit --- examples/bubble/bubble.py | 106 +------------------------------ examples/bubble/conf/bubble.yaml | 20 +----- 2 files changed, 3 insertions(+), 123 deletions(-) diff --git a/examples/bubble/bubble.py b/examples/bubble/bubble.py index 6806e91a4..dd0e076db 100644 --- a/examples/bubble/bubble.py +++ b/examples/bubble/bubble.py @@ -403,117 +403,15 @@ def transform_out(in_, out): ) -def export(cfg: DictConfig): - # set model - model_psi = ppsci.arch.MLP(**cfg.MODEL.psi_net) - model_p = ppsci.arch.MLP(**cfg.MODEL.p_net) - model_phil = ppsci.arch.MLP(**cfg.MODEL.phil_net) - - # transform - def transform_out(in_, out): - psi_y = out["psi"] - y = in_["y"] - x = in_["x"] - u = jacobian(psi_y, y, create_graph=False) - v = -jacobian(psi_y, x, create_graph=False) - return {"u": u, "v": v} - - # register transform - model_psi.register_output_transform(transform_out) - model_list = ppsci.arch.ModelList((model_psi, model_p, model_phil)) - - # initialize solver - solver = ppsci.solver.Solver( - model_list, - pretrained_model_path=cfg.INFER.pretrained_model_path, - ) - # export model - from paddle.static import InputSpec - input_spec = [ - InputSpec(shape=[None, 1], dtype="float32", name="t"), - InputSpec(shape=[None, 1], dtype="float32", name="x"), - InputSpec(shape=[None, 1], dtype="float32", name="y"), - ] - solver.export(input_spec, cfg.INFER.export_path) - - -def inference(cfg: DictConfig): - # load Data - data = scipy.io.loadmat(cfg.DATA_PATH) - # normalize data - p_max = data["p"].max(axis=0) - p_min = data["p"].min(axis=0) - u_max = data["u"].max(axis=0) - u_min = data["u"].min(axis=0) - v_max = data["v"].max(axis=0) - v_min = data["v"].min(axis=0) - - from deploy.python_infer import pinn_predictor - - predictor = pinn_predictor.PINNPredictor(cfg) - # set time-geometry - timestamps = np.linspace(0, 126, 127, endpoint=True) - geom = { - "time_rect_visu": ppsci.geometry.TimeXGeometry( - ppsci.geometry.TimeDomain(1, 126, timestamps=timestamps), - ppsci.geometry.Rectangle((0, 0), (15, 5)), - ), - } - NTIME_ALL = len(timestamps) - NPOINT_PDE, NTIME_PDE = 300 * 100, NTIME_ALL - 1 - input_dict = geom["time_rect_visu"].sample_interior( - NPOINT_PDE * NTIME_PDE, evenly=True - ) - output_dict = predictor.predict(input_dict, cfg.INFER.batch_size) - - # mapping data to cfg.INFER.output_keys - output_dict = { - store_key: output_dict[infer_key] - for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys()) - } - - # inverse normalization - p_pred = output_dict["p"].reshape([NTIME_PDE, NPOINT_PDE]).T - u_pred = output_dict["u"].reshape([NTIME_PDE, NPOINT_PDE]).T - v_pred = output_dict["v"].reshape([NTIME_PDE, NPOINT_PDE]).T - pred = { - "p": (p_pred * (p_max - p_min) + p_min).T.reshape([-1, 1]), - "u": (u_pred * (u_max - u_min) + u_min).T.reshape([-1, 1]), - "v": (v_pred * (v_max - v_min) + v_min).T.reshape([-1, 1]), - "phil": output_dict["phil"], - } - ppsci.visualize.save_vtu_from_dict( - osp.join(cfg.output_dir, "visual/result.vtu"), - { - "t": input_dict["t"], - "x": input_dict["x"], - "y": input_dict["y"], - "u": pred["u"], - "v": pred["v"], - "p": pred["p"], - "phil": pred["phil"], - }, - ("t", "x", "y"), - ("u", "v", "p", "phil"), - NTIME_PDE, - ) - - @hydra.main(version_base=None, config_path="./conf", config_name="bubble.yaml") def main(cfg: DictConfig): if cfg.mode == "train": train(cfg) elif cfg.mode == "eval": evaluate(cfg) - elif cfg.mode == "export": - export(cfg) - elif cfg.mode == "infer": - inference(cfg) else: - raise ValueError( - f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'" - ) + raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'") if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/examples/bubble/conf/bubble.yaml b/examples/bubble/conf/bubble.yaml index dcceff01a..6b77e35a3 100644 --- a/examples/bubble/conf/bubble.yaml +++ b/examples/bubble/conf/bubble.yaml @@ -64,22 +64,4 @@ TRAIN: # evaluation settings EVAL: pretrained_model_path: null - eval_with_no_grad: true - -# inference settings -INFER: - pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/bubble/bubble_pretrained.pdparams - export_path: ./inference/bubble - pdmodel_path: ${INFER.export_path}.pdmodel - pdiparams_path: ${INFER.export_path}.pdiparams - onnx_path: ${INFER.export_path}.onnx - device: gpu - engine: native - precision: fp32 - ir_optim: true - min_subgraph_size: 5 - gpu_mem: 2000 - gpu_id: 0 - max_batch_size: 1024 - num_cpu_threads: 10 - batch_size: 1024 + eval_with_no_grad: true \ No newline at end of file From 9af1f8587f5f78eda2bfbf7b0953ff0bd8ca64a6 Mon Sep 17 00:00:00 2001 From: wufei Date: Thu, 9 May 2024 18:00:29 +0800 Subject: [PATCH 14/22] fix codestyle bugs --- examples/bubble/bubble.py | 2 +- examples/bubble/conf/bubble.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/bubble/bubble.py b/examples/bubble/bubble.py index dd0e076db..86ce46a2a 100644 --- a/examples/bubble/bubble.py +++ b/examples/bubble/bubble.py @@ -414,4 +414,4 @@ def main(cfg: DictConfig): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/examples/bubble/conf/bubble.yaml b/examples/bubble/conf/bubble.yaml index 6b77e35a3..40262276a 100644 --- a/examples/bubble/conf/bubble.yaml +++ b/examples/bubble/conf/bubble.yaml @@ -64,4 +64,4 @@ TRAIN: # evaluation settings EVAL: pretrained_model_path: null - eval_with_no_grad: true \ No newline at end of file + eval_with_no_grad: true From b60953e478175dbb3afaa23331d13481d607d32c Mon Sep 17 00:00:00 2001 From: HydrogenSulfate <490868991@qq.com> Date: Thu, 9 May 2024 21:07:51 +0800 Subject: [PATCH 15/22] Update examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py --- examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py b/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py index 379646090..79ba6d4e4 100644 --- a/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py +++ b/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py @@ -330,9 +330,9 @@ def export(cfg: DictConfig): def inference(cfg: DictConfig): - from deploy.python_infer import pinn_predictor + from deploy import python_infer - predictor = pinn_predictor.PINNPredictor(cfg) + predictor = python_infer.GeneralPredictor(cfg) # set time-geometry geom = { "time_rect_eval": ppsci.geometry.PointCloud( From 1b62517bf397514d855243f0855406cd2d2a1716 Mon Sep 17 00:00:00 2001 From: HydrogenSulfate <490868991@qq.com> Date: Fri, 10 May 2024 10:30:23 +0800 Subject: [PATCH 16/22] Update examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py --- .../transformer_physx/train_transformer.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py index 0b767f024..97a1e17aa 100644 --- a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py +++ b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py @@ -292,22 +292,9 @@ def export(cfg: DictConfig): def inference(cfg: DictConfig): - from deploy.python_infer import base - - predictor = base.Predictor( - cfg.INFER.pdmodel_path, - cfg.INFER.pdiparams_path, - device=cfg.INFER.device, - engine=cfg.INFER.engine, - precision=cfg.INFER.precision, - onnx_path=cfg.INFER.onnx_path, - ir_optim=cfg.INFER.ir_optim, - min_subgraph_size=cfg.INFER.min_subgraph_size, - gpu_mem=cfg.INFER.gpu_mem, - gpu_id=cfg.INFER.gpu_id, - max_batch_size=cfg.INFER.max_batch_size, - num_cpu_threads=cfg.INFER.num_cpu_threads, - ) + from deploy import python_infer + + predictor = python_infer.GeneralPredictor(cfg) dataset_cfg = { "name": "CylinderDataset", From f6f3e76a6067883bb0639d19020eecfa40af303d Mon Sep 17 00:00:00 2001 From: HydrogenSulfate <490868991@qq.com> Date: Fri, 10 May 2024 10:30:28 +0800 Subject: [PATCH 17/22] Update examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py --- examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py b/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py index 79ba6d4e4..379646090 100644 --- a/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py +++ b/examples/cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py @@ -330,9 +330,9 @@ def export(cfg: DictConfig): def inference(cfg: DictConfig): - from deploy import python_infer + from deploy.python_infer import pinn_predictor - predictor = python_infer.GeneralPredictor(cfg) + predictor = pinn_predictor.PINNPredictor(cfg) # set time-geometry geom = { "time_rect_eval": ppsci.geometry.PointCloud( From 6368b7b588c8c657484d19dff9ae875ffcdb259c Mon Sep 17 00:00:00 2001 From: wufei Date: Fri, 10 May 2024 15:07:30 +0800 Subject: [PATCH 18/22] Update examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py --- .../transformer_physx/train_transformer.py | 21 ++++--------------- examples/rossler/train_transformer.py | 12 ++--------- ppsci/arch/physx_transformer.py | 6 +++++- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py index 0b767f024..e703af1fd 100644 --- a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py +++ b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py @@ -283,7 +283,7 @@ def export(cfg: DictConfig): input_spec = [ { - key: InputSpec([None, 255, 128], "float32", name=key) + key: InputSpec([None, 16, 128], "float32", name=key) for key in model.input_keys }, ] @@ -292,22 +292,9 @@ def export(cfg: DictConfig): def inference(cfg: DictConfig): - from deploy.python_infer import base - - predictor = base.Predictor( - cfg.INFER.pdmodel_path, - cfg.INFER.pdiparams_path, - device=cfg.INFER.device, - engine=cfg.INFER.engine, - precision=cfg.INFER.precision, - onnx_path=cfg.INFER.onnx_path, - ir_optim=cfg.INFER.ir_optim, - min_subgraph_size=cfg.INFER.min_subgraph_size, - gpu_mem=cfg.INFER.gpu_mem, - gpu_id=cfg.INFER.gpu_id, - max_batch_size=cfg.INFER.max_batch_size, - num_cpu_threads=cfg.INFER.num_cpu_threads, - ) + from deploy import python_infer + + predictor = python_infer.GeneralPredictor(cfg) dataset_cfg = { "name": "CylinderDataset", diff --git a/examples/rossler/train_transformer.py b/examples/rossler/train_transformer.py index a58b8b8d2..2973d3571 100644 --- a/examples/rossler/train_transformer.py +++ b/examples/rossler/train_transformer.py @@ -246,14 +246,7 @@ def evaluate(cfg: DictConfig): def export(cfg: DictConfig): # set model - embedding_model = build_embedding_model(cfg.EMBEDDING_MODEL_PATH) - model_cfg = { - **cfg.MODEL, - "embedding_model": embedding_model, - "input_keys": ["states"], - "output_keys": ["pred_states"], - } - model = ppsci.arch.PhysformerGPT2(**model_cfg) + model = ppsci.arch.PhysformerGPT2(**cfg.MODEL) # initialize solver solver = ppsci.solver.Solver( @@ -265,11 +258,10 @@ def export(cfg: DictConfig): input_spec = [ { - key: InputSpec([None, 255, 3], "float32", name=key) + key: InputSpec([None, 16, 128], "float32", name=key) for key in model.input_keys }, ] - solver.export(input_spec, cfg.INFER.export_path) diff --git a/ppsci/arch/physx_transformer.py b/ppsci/arch/physx_transformer.py index e3fc5e510..267fb458c 100644 --- a/ppsci/arch/physx_transformer.py +++ b/ppsci/arch/physx_transformer.py @@ -28,6 +28,7 @@ from paddle.nn.initializer import Normal from ppsci.arch import base +from ppsci.arch.embedding_koopman import CylinderEmbedding zeros_ = Constant(value=0.0) ones_ = Constant(value=1.0) @@ -387,7 +388,10 @@ def forward(self, x): x = self._input_transform(x) x_tensor = self.concat_to_tensor(x, self.input_keys, axis=-1) if self.embedding_model is not None: - x_tensor = self.embedding_model.encoder(x_tensor) + if isinstance(self.embedding_model, CylinderEmbedding): + x_tensor = self.embedding_model.encoder(x_tensor, x["visc"]) + else: + x_tensor = self.embedding_model.encoder(x_tensor) if self.training: y = self.forward_tensor(x_tensor) From 2f751802a71aab777de979a065c3efb9c6d55037 Mon Sep 17 00:00:00 2001 From: wufei Date: Fri, 10 May 2024 15:22:06 +0800 Subject: [PATCH 19/22] Update examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py --- .../cylinder/2d_unsteady/transformer_physx/train_transformer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py index e703af1fd..c68b92b0c 100644 --- a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py +++ b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py @@ -263,6 +263,7 @@ def evaluate(cfg: DictConfig): def export(cfg: DictConfig): + # set model embedding_model = build_embedding_model(cfg.EMBEDDING_MODEL_PATH) model_cfg = { From d0581985d0d8ad430815f81821edf7a7c7333537 Mon Sep 17 00:00:00 2001 From: wufei Date: Fri, 10 May 2024 15:26:15 +0800 Subject: [PATCH 20/22] cancel extra changes --- .../transformer_physx/train_transformer.py | 1 - examples/rossler/train_transformer.py | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py index c68b92b0c..e703af1fd 100644 --- a/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py +++ b/examples/cylinder/2d_unsteady/transformer_physx/train_transformer.py @@ -263,7 +263,6 @@ def evaluate(cfg: DictConfig): def export(cfg: DictConfig): - # set model embedding_model = build_embedding_model(cfg.EMBEDDING_MODEL_PATH) model_cfg = { diff --git a/examples/rossler/train_transformer.py b/examples/rossler/train_transformer.py index 2973d3571..db1b51d9a 100644 --- a/examples/rossler/train_transformer.py +++ b/examples/rossler/train_transformer.py @@ -246,7 +246,14 @@ def evaluate(cfg: DictConfig): def export(cfg: DictConfig): # set model - model = ppsci.arch.PhysformerGPT2(**cfg.MODEL) + embedding_model = build_embedding_model(cfg.EMBEDDING_MODEL_PATH) + model_cfg = { + **cfg.MODEL, + "embedding_model": embedding_model, + "input_keys": ["states"], + "output_keys": ["pred_states"], + } + model = ppsci.arch.PhysformerGPT2(**model_cfg) # initialize solver solver = ppsci.solver.Solver( @@ -258,7 +265,7 @@ def export(cfg: DictConfig): input_spec = [ { - key: InputSpec([None, 16, 128], "float32", name=key) + key: InputSpec([None, 255, 3], "float32", name=key) for key in model.input_keys }, ] From 0ea2af6fbdc07e1a830e5882a8accf4d02a8ac68 Mon Sep 17 00:00:00 2001 From: wufei Date: Fri, 10 May 2024 15:28:45 +0800 Subject: [PATCH 21/22] cancel extra changes --- examples/rossler/train_transformer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/rossler/train_transformer.py b/examples/rossler/train_transformer.py index db1b51d9a..a58b8b8d2 100644 --- a/examples/rossler/train_transformer.py +++ b/examples/rossler/train_transformer.py @@ -269,6 +269,7 @@ def export(cfg: DictConfig): for key in model.input_keys }, ] + solver.export(input_spec, cfg.INFER.export_path) From d0a5d37f619c8dd6885f4c5c60d2094e791ef07d Mon Sep 17 00:00:00 2001 From: wufei Date: Fri, 10 May 2024 15:43:52 +0800 Subject: [PATCH 22/22] update examples/cylinder/2d_unsteady/transformer_physx/conf/transformer.yaml --- .../2d_unsteady/transformer_physx/conf/transformer.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/cylinder/2d_unsteady/transformer_physx/conf/transformer.yaml b/examples/cylinder/2d_unsteady/transformer_physx/conf/transformer.yaml index f5b97cd9b..20003f2a7 100644 --- a/examples/cylinder/2d_unsteady/transformer_physx/conf/transformer.yaml +++ b/examples/cylinder/2d_unsteady/transformer_physx/conf/transformer.yaml @@ -28,6 +28,7 @@ TRAIN_BLOCK_SIZE: 16 VALID_BLOCK_SIZE: 256 TRAIN_FILE_PATH: ./datasets/cylinder_training.hdf5 VALID_FILE_PATH: ./datasets/cylinder_valid.hdf5 +log_freq: 20 # set working condition EMBEDDING_MODEL_PATH: ./outputs_cylinder2d_unsteady_transformer_physx_enn/checkpoints/latest @@ -37,7 +38,7 @@ VIS_DATA_NUMS: 1 MODEL: input_keys: ["embeds"] output_keys: ["pred_embeds"] - num_layers: 4 + num_layers: 6 num_ctx: 16 embed_size: 128 num_heads: 4 @@ -77,6 +78,6 @@ INFER: min_subgraph_size: 10 gpu_mem: 4000 gpu_id: 0 - max_batch_size: 16 + max_batch_size: 64 num_cpu_threads: 4 batch_size: 16