diff --git a/docs/zh/examples/ldc2d_steady.md b/docs/zh/examples/ldc2d_steady.md index ca63c373b..47dee00fe 100644 --- a/docs/zh/examples/ldc2d_steady.md +++ b/docs/zh/examples/ldc2d_steady.md @@ -205,13 +205,13 @@ $$ ### 3.1 模型构建 在 2D-LDC 问题中,每一个已知的坐标点 $(x, y)$ 都有自身的横向速度 $u$、纵向速度 $v$、压力 $p$ -三个待求解的未知量,我们在这里使用比较简单的 MLP(Multilayer Perceptron, 多层感知机) 来表示 $(x, y)$ 到 $(u, v, p)$ 的映射函数 $f: \mathbb{R}^2 \to \mathbb{R}^3$ ,即: +三个待求解的未知量,我们在这里使用适合于 PINN 任务的 PirateNet 来表示 $(x, y)$ 到 $(u, v, p)$ 的映射函数 $f: \mathbb{R}^2 \to \mathbb{R}^3$ ,即: $$ u, v, p = f(x, y) $$ -上式中 $f$ 即为 MLP 模型本身,用 PaddleScience 代码表示如下 +上式中 $f$ 即为 `PirateNet` 模型本身,用 PaddleScience 代码表示如下 ``` py linenums="41" --8<-- diff --git a/docs/zh/quickstart.md b/docs/zh/quickstart.md index a38a9e409..06da4d258 100644 --- a/docs/zh/quickstart.md +++ b/docs/zh/quickstart.md @@ -148,7 +148,7 @@ examples/quick_start/case1.py 虽然无法求出解析式直接构造监督数据,但往往可以利用相关数学知识,推导出目标拟合函数符合的某种数学关系,以训练模型以满足这种数学关系的方式,达到以“间接监督”的方式优化模型的目的。 -假设我们不再使用 $u=\sin(x)$ 这一先验公式,因而无法计算标签数据 $u$。因此我们使用如下方程组,其含有一个偏微分方程和边界条件 +假设我们不再使用 $u=\sin(x)$ 这一先验公式,因而无法计算标签数据 $u$。因此使用如下方程组,其含有一个偏微分方程和边界条件 $$ \begin{cases} diff --git a/docs/zh/user_guide.md b/docs/zh/user_guide.md index da78dc4fc..c3f070af9 100644 --- a/docs/zh/user_guide.md +++ b/docs/zh/user_guide.md @@ -492,7 +492,7 @@ PaddleScience 提供了多种推理配置组合,可通过命令行进行组合 === "方式2: 修改代码" - 因此我们只需要在 `Solver` 时指定 `checkpoint_path` 参数为 `latest.*` 的所在路径,即可自动载入上述的几个文件,并从 `latest` 中记录的 epoch 开始继续训练。 + 只需要在 `Solver` 时指定 `checkpoint_path` 参数为 `latest.*` 的所在路径,即可自动载入上述的几个文件,并从 `latest` 中记录的 epoch 开始继续训练。 ``` py hl_lines="7" import ppsci @@ -993,7 +993,7 @@ TODO --> ## 3. 使用 Nsight 进行性能分析 -Nsight是NVIDIA面相开发者提供的开发工具套件,能提供深入的跟踪、调试、评测和分析,以优化跨 NVIDIA GPU和CPU的复杂计算应用程序。详细文档可参考:[Nsight Systems Document](https://docs.nvidia.com/nsight-systems/index.html) +Nsight是NVIDIA面向开发者提供的开发工具套件,能提供深入的跟踪、调试、评测和分析,以优化跨 NVIDIA GPU和CPU的复杂计算应用程序。详细文档可参考:[Nsight Systems Document](https://docs.nvidia.com/nsight-systems/index.html) PaddleScience 初步支持使用 Nsight 进行性能分析,以 linux 开发环境 + laplace2d 案例为例,按照如下步骤使用 nsight 工具生成性能分析报告并查看分析结果。 diff --git a/ppsci/utils/__init__.py b/ppsci/utils/__init__.py index f397f090a..fa81a2fc6 100644 --- a/ppsci/utils/__init__.py +++ b/ppsci/utils/__init__.py @@ -19,7 +19,6 @@ from ppsci.utils import initializer from ppsci.utils import logger from ppsci.utils import misc -from ppsci.utils import profiler from ppsci.utils import reader from ppsci.utils import writer from ppsci.utils.checker import dynamic_import_to_globals @@ -49,7 +48,6 @@ "ema", "reader", "writer", - "profiler", "load_csv_file", "load_mat_file", "load_npz_file", diff --git a/ppsci/utils/profiler.py b/ppsci/utils/profiler.py deleted file mode 100644 index 48a68a46b..000000000 --- a/ppsci/utils/profiler.py +++ /dev/null @@ -1,152 +0,0 @@ -# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import annotations - -import functools -import sys -import time -from typing import Callable - -import paddle - -# A global variable to record the number of calling times for profiler -# functions. It is used to specify the tracing range of training steps. -_profiler_step_id = 0 - -# A global variable to avoid parsing from string every time. -_profiler_options = None - - -class ProfilerOptions: - """ - Use a string to initialize a ProfilerOptions. - The string should be in the format: "key1=value1;key2=value;key3=value3". - For example: - "profile_path=model.profile" - "batch_range=[50, 60]; profile_path=model.profile" - "batch_range=[50, 60]; tracer_option=OpDetail; profile_path=model.profile" - - ProfilerOptions supports following key-value pair: - batch_range - a integer list, e.g. [100, 110]. - state - a string, the optional values are "CPU", "GPU" or "All". - sorted_key - a string, the optional values are "calls", "total", - "max", "min" or "ave. - tracer_option - a string, the optional values are "Default", "OpDetail", - "AllOpDetail". - profile_path - a string, the path to save the serialized profile data, - which can be used to generate a timeline. - exit_on_finished - a boolean. - """ - - def __init__(self, options_str): - if not isinstance(options_str, str): - raise ValueError() - - self._options = { - "batch_range": [10, 20], - "state": "All", - "sorted_key": "total", - "tracer_option": "Default", - "profile_path": "/tmp/profile", - "exit_on_finished": True, - } - self._parse_from_string(options_str) - - def _parse_from_string(self, options_str): - for kv in options_str.replace(" ", "").split(";"): - key, value = kv.split("=") - if key == "batch_range": - value_list = value.replace("[", "").replace("]", "").split(",") - value_list = list(map(int, value_list)) - if ( - len(value_list) >= 2 - and value_list[0] >= 0 - and value_list[1] > value_list[0] - ): - self._options[key] = value_list - elif key == "exit_on_finished": - self._options[key] = value.lower() in ("yes", "true", "t", "1") - elif key in ["state", "sorted_key", "tracer_option", "profile_path"]: - self._options[key] = value - - def __getitem__(self, name): - if self._options.get(name, None) is None: - raise ValueError(f"ProfilerOptions does not have an option named {name}.") - return self._options[name] - - -def add_profiler_step(options_str: str = None): - """ - Enable the operator-level timing using PaddlePaddle"s profiler. - The profiler uses a independent variable to count the profiler steps. - One call of this function is treated as a profiler step. - - Args: - options_stra (str, optional): string to initialize the ProfilerOptions. - Default is None, and the profiler is disabled. - """ - if options_str is None: - return - - global _profiler_step_id - global _profiler_options - - if _profiler_options is None: - _profiler_options = ProfilerOptions(options_str) - - if _profiler_step_id == _profiler_options["batch_range"][0]: - paddle.utils.profiler.start_profiler( - _profiler_options["state"], _profiler_options["tracer_option"] - ) - elif _profiler_step_id == _profiler_options["batch_range"][1]: - paddle.utils.profiler.stop_profiler( - _profiler_options["sorted_key"], _profiler_options["profile_path"] - ) - if _profiler_options["exit_on_finished"]: - sys.exit(0) - - _profiler_step_id += 1 - - -def timing(func: Callable) -> Callable: - """Get time cost for given function. - - Args: - func (Callable): Function to be tested. - - Returns: - Callable: Wrapped function with time.perf_counter() at begin and end. - - Examples: - >>> from ppsci.utils import profiler - >>> @profiler.timing - ... def my_func(): - ... x = 0 - ... for i in range(20): - ... x += i - ... return x - >>> # Time cost of [my_func] is 0.00(s). - """ - - @functools.wraps(func) - def wrapped_func(*args, **kwargs): - s = time.perf_counter() - result = func(*args, **kwargs) - t = time.perf_counter() - cost = t - s - print(f"Time cost of [{func.__name__}] is {cost:.2f}(s).") - return result - - return wrapped_func diff --git a/requirements.txt b/requirements.txt index 17205eaec..2265297fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,6 @@ meshio==5.3.4 numpy>=1.20.0,<=1.23.1 pydantic>=2.5.0 pyevtk -pyvista==0.37.0 pyyaml scikit-learn<1.5.0 scikit-optimize @@ -16,5 +15,4 @@ seaborn sympy tqdm typing-extensions -vtk wget