Skip to content
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

update HMC API #541

Merged
merged 3 commits into from
Sep 18, 2023
Merged

update HMC API #541

merged 3 commits into from
Sep 18, 2023

Conversation

NKNaN
Copy link
Contributor

@NKNaN NKNaN commented Sep 14, 2023

Describe

  • 将API的目标参数按照Pyro的API调整为集合形式,以便对多个参数同时进行采样。
  • run_chain中增加warmup阶段。
  • 新增测试案例。

Future Work

如果需要达到和Pyro等一样的速度需要在采样时加入调整步长的功能。

@CLAassistant
Copy link

CLAassistant commented Sep 14, 2023

CLA assistant check
All committers have signed the CLA.

@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Sep 15, 2023
from paddle.distribution import Normal
from paddle.distribution import Uniform

from ppsci.utils import set_random_seed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==> from ppsci import utils

Comment on lines 19 to 20
from paddle.distribution import Normal
from paddle.distribution import Uniform
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==> from paddle import distribution

@@ -12,95 +12,149 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from collections import OrderedDict
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python>=3.7 的dict应该是默认与添加顺序保持一致的,可以不使用这个OrderedDict

"""

def __init__(self, tensor: paddle.Tensor):
self.tensor = tensor
def __init__(self, tensor_dict: OrderedDict):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==> Dict[str, paddle.Tensor]

Comment on lines +67 to +68
num_warmup_steps: int = 0,
random_seed: int = 1024,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring添加一下这两个参数

num_warmup_steps: int = 0,
random_seed: int = 1024,
):
self.dist = distribution_fn
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==> self.distribution_fn

Comment on lines 148 to 149
q0_nlp = -self.dist(**q0)
q1_nlp = -self.dist(**q1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后缀_nlp表示什么意思呢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是之前pr的朋友写的,我没改,可能是negative log probability吧。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是之前pr的朋友写的,我没改,可能是negative log probability吧。

这个命名感觉不太好,可以在上方加一个带有全称的注释说明nlp的意义


acceptance = paddle.minimum(
paddle.to_tensor(1.0), paddle.exp((q0_nlp + p0_nlp) - (p1_nlp + q1_nlp))
)

# whether accept the proposed state position
event = paddle.uniform(shape=[], min=0, max=1)
event = self._rv_unif.sample([1]).squeeze()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paddle已经支持0-D tensor,可以试试直接使用[]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

完善一下每个函数的type hint,包括入参和返回类型

@NKNaN
Copy link
Contributor Author

NKNaN commented Sep 16, 2023

from ppsci import utils似乎会报错
image

其它的已经修改

@HydrogenSulfate
Copy link
Collaborator

from ppsci import utils似乎会报错 image

其它的已经修改

这个应该是因为没有安装 colorlog 这个包,可以执行一下 pip install -r requirements.txt

@NKNaN
Copy link
Contributor Author

NKNaN commented Sep 16, 2023

from ppsci import utils似乎会报错 image
其它的已经修改

这个应该是因为没有安装 colorlog 这个包,可以执行一下 pip install -r requirements.txt

OK那应该没问题了

Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HydrogenSulfate HydrogenSulfate merged commit dadf6be into PaddlePaddle:develop Sep 18, 2023
3 checks passed
@luotao1
Copy link
Collaborator

luotao1 commented Sep 19, 2023

hi, @NKNaN

  • 非常感谢你对飞桨框架的贡献,我们正在运营一个PFCC组织,会通过定期分享技术知识与发布开发者主导任务的形式持续为飞桨框架做贡献,详情可见 https://github.com/luotao1 主页说明。
  • 如果你对PFCC有兴趣,请发送邮件至 ext_paddle_oss@baidu.com,我们会邀请你加入~
  • 飞桨护航计划集训营火热进行中:开发者提交简历&通过面试后,以远程的方式深度参与飞桨重要开源项目开发实践,成果以 PR(Pull Requests)的形式贡献到指定代码仓库,实训期 3 个月(每周开发时间至少25h),奖金 6000-10000。有兴趣的话,可以报一下赛题13 科学计算领域拓展专项

@luotao1 luotao1 added HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 and removed HappyOpenSource 快乐开源活动issue与PR labels Nov 20, 2023
@NKNaN NKNaN deleted the ayase/develop branch December 26, 2023 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants