-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Hackathon 6th Code Camp No.15] support neuraloperator #867
[Hackathon 6th Code Camp No.15] support neuraloperator #867
Conversation
Thanks for your contribution! |
ppsci/arch/fno_block.py
Outdated
except KeyError: | ||
padding = [round(p * r) for (p, r) in zip(self.domain_padding, resolution)] | ||
|
||
print( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议使用ppsci内置的log
ppsci/arch/fno_block.py
Outdated
# of the "padding" list i.e. the last axis of tensor 'x' will be | ||
# padded by the amount mention at the first position of the | ||
# 'padding' vector. The details about F.pad can be found here: | ||
# https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确认注释正确性
ppsci/arch/fno_block.py
Outdated
padded = F.pad(x, padding, mode="constant") | ||
|
||
output_shape = padded.shape[2:] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除多余空格
ppsci/arch/fno_block.py
Outdated
return nn.Identity() | ||
else: | ||
raise ValueError( | ||
f"Got skip-connection type = {type}, expected one of {'soft-gating', 'linear', 'id'}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id --> identity
ppsci/arch/fno_block.py
Outdated
arg is only checked when `implementation=reconstructed`. Defaults to False. | ||
|
||
Raises: | ||
ValueError: _description_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除raises
ppsci/arch/fno_block.py
Outdated
|
||
if implementation == "reconstructed": | ||
if separable: | ||
print("SEPARABLE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除print
ppsci/arch/fno_block.py
Outdated
# elif weight.name.lower() == 'complexcp': | ||
# return _contract_cp | ||
# else: | ||
# raise ValueError(f'Got unexpected factorized weight type {weight.name}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除无意义的注释
ppsci/arch/fno_block.py
Outdated
fixed_rank_modes=False, | ||
joint_factorization=False, | ||
init_std="auto", | ||
fft_norm="backward", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
初始化添加类型提示,其他的 类 也注意一下
ppsci/arch/fno_block.py
Outdated
) | ||
|
||
def forward( | ||
self, x: paddle.Tensor, indices=0, output_shape: Optional[Tuple[int]] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
变量 indices 添加类型提示
|
||
This is provided for reference only, | ||
see :class:`neuralop.layers.SpectraConv` for the preferred, general implementation | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
更正注释,ppsci没有neuralop.layers.SpectraConv
这个路径,另外确认该类是否在代码中有用到
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这几个类都没有用到,但是是可选的
…/PaddleScience into add_neuraloperator
|
||
|
||
def _contract_dense_trick(x, weight_real, weight_imag, separable=False, dhconv=True): | ||
# the same as above function, but do the complex multiplication manually to avoid the einsum bug in paddle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“the same as above function” ?这个函数上面没有其他函数呀?
ppsci/arch/sfnonet.py
Outdated
|
||
if implementation == "reconstructed": | ||
if separable: | ||
print("SEPARABLE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确认是否有必要print
ppsci/arch/sfnonet.py
Outdated
elif implementation == "factorized": | ||
if isinstance(weight, paddle.Tensor): | ||
return _contract_dense_trick | ||
# TODO: FactorizedTensor not supported yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个注释可以删掉吧
ppsci/arch/sfnonet.py
Outdated
|
||
|
||
class SphericalConv(nn.Layer): | ||
"""Spherical Convolution, base class for the SFNO [1]_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释最后用“.“更合适吧?
"""Spherical Convolution, base class for the SFNO [1]. | ||
.. [1] Spherical Fourier Neural Operators: Learning Stable Dynamics on the Sphere, | ||
Boris Bonev, Thorsten Kurth, Christian Hundt, Jaideep Pathak, Maximilian Baust, Karthik Kashinath, Anima Anandkumar, | ||
ICML 2023. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
references重复了
ppsci/arch/sfnonet.py
Outdated
Args: | ||
in_channels (int): Number of input channels. | ||
out_channels (int): Number of output channels. | ||
n_modes (int): Number of modes to use for contraction in Fourier domain during |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释中的变量类型与初始化函数中的保持一致
ppsci/arch/fno_block.py
Outdated
"""Applies domain padding scaled automatically to the input's resolution | ||
|
||
Args: | ||
domain_padding (float): typically, between zero and one, percentage of padding to use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
类型与初始化代码保持一致, Union[float, List[float]]
|
||
Returns | ||
------- | ||
torch.tensor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数注释修改下,建议注释风格修改为PaddleScience风格
|
||
# x is in shape of batch*n or T*batch*n | ||
# x = (x.view(self.sample_shape) * std) + mean | ||
# x = x.view(-1, *self.sample_shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要的注释删除吧
return x | ||
|
||
|
||
def count_params(model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确认此函数是否有使用
50 samples at resolution 32x32. | ||
|
||
Args: | ||
test_resolutions (List[int,...]): The resolutions to test dataset. Default is [16, 32]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
完善docstring,与初始化函数的入参保持一致, 缺少train_resolution,记得补充完整。test_resolutions参数的docstring的默认值也需要与初始化入参保持一致
50 samples at resolution 64x128. | ||
|
||
Args: | ||
test_resolutions (List[str,...]): The resolutions to test dataset. Default is ["34x64","64x128"]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
完善docstring
… into add_neuraloperator
…/PaddleScience into add_neuraloperator
docs/zh/api/data/dataset.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
添加 SphericalSWEDataset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为这个数据集是我使用pytorch原代码生成的数据,直接保存的npy文件,这样还需要写进去吗
pretrained_model_path: ./outputs_sfno_pretrain/checkpoints/best_model.pdparams | ||
export_path: ./inference/uno/uno_darcyflow | ||
pdmodel_path: ${INFER.export_path}.pdmodel | ||
pdpiparams_path: ${INFER.export_path}.pdiparams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pdpiparams_path --> pdiparams_path 全部替换一下
encoding (str): The type of encoding. Default is 'channel-wise'. | ||
channel_dim (int): The location of unsqueeze. Default is 1. | ||
where to put the channel dimension, defaults size is batch, channel, height, width | ||
training (str): Wether to use training or test dataset. Default is 'train'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其他数据集中使用 training 参数表示该数据集是否用于训练,使用bool类型。在此数据集中,training 参数还用于表示测试时的数据选择,与变量名称”training“不太相符,建议修改为其他更有意义的变量名称
Defaults to None. | ||
test_resolutions (Tuple[str, ...], optional): The resolutions to test dataset. Defaults to ["34x64", "64x128"]. | ||
train_resolution (str, optional): The resolutions to train dataset. Defaults to "34x64". | ||
training (str, optional): Wether to use training or test dataset. Defaults to "train". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
与本PR无关,记得删除
input_data = data["x"][0].reshape(1, *data["x"].shape[1:]).astype("float32") | ||
label = data["y"][0][0, ...].astype("float32") | ||
|
||
model = ppsci.arch.SFNONet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好像还是使用动态图的形式进行预测的?并没有使用export的静态图模型进行预测?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是动态图形式进行预测的,因为导出静态图模型进行预测时,结果和动态图不一样,可能是因为使用虚数的缘故,也可能是独有的API导致的导出模型的网络权重有问题,跟动态图的网络权重不一样,这个之前给你说过
…/PaddleScience into add_neuraloperator
…/PaddleScience into add_neuraloperator
paddle使用dev版本 |
examples/neuraloperator/train_uno.py
Outdated
sup_validator_32.name: sup_validator_32, | ||
} | ||
|
||
model = ppsci.arch.TFNO2dNet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方应该是UNO的模型吧
scheduler_T_max: 500 | ||
wd: 1.0e-4 | ||
batch_size: 16 | ||
pretrained_model_path: ./pretrainmodel/tfno_pretrain.pdparams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接设置成null吧,另外两个也改下
ppsci/arch/fno_block.py
Outdated
n_layers: int = 1, | ||
max_n_modes: int = None, | ||
use_mlp: bool = False, | ||
mlp: Optional[dict[float, float]] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处dict应该为Dict, 并在文件开头添加:from typing import Dict,其他文件也有类似问题,建议统一检查
examples/neuraloperator/train_uno.py
Outdated
ax.set_title("Model prediction") | ||
plt.xticks([], []) | ||
plt.yticks([], []) | ||
plt.savefig(cfg.output_dir + "123.png") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处123.png,作为文件名称有什么含义么
solver.export(input_spec, cfg.INFER.export_path) | ||
|
||
|
||
# 使用静态图推理出错 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在推理还有问题么
examples/neuraloperator/predictor.py
Outdated
""" | ||
if batch_size != 1: | ||
raise ValueError( | ||
f"FNOPredictor only support batch_size=1, but got {batch_size}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FNOPredictor --> SFNOPredictor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, TODO:add doc
PR types
New features
PR changes
Others
Describe
增加neuraloperator模型