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

[Refine] Remove redundant code #852

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from

Conversation

HydrogenSulfate
Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate commented Apr 16, 2024

PR types

Function optimization

PR changes

Others

Describe

  1. 删除随机种子固定、logger初始化代码,在yaml中通过callback控制,如下所示

    # set random seed for reproducibility
    ppsci.utils.misc.set_random_seed(cfg.seed)
    # initialize logger
    logger.init_logger("ppsci", osp.join(cfg.output_dir, "train.log"), "info")
  2. 当drop_last和shuffle均为False时,可以省略sampler配置字段,删除如下冗余代码

    "sampler": {
        "name": "BatchSampler",
        "drop_last": False,
        "shuffle": False,
    },
  3. num_workers默认为1,因此删除手动指定的代码。

  4. 配置文件添加默认值SolverConfig,化简config模块相关代码,当指定了cfg参数时,不需要传入除model、constraint、equation、validator等必要参数之外的其他超参数,否则保持原状,兼容已有代码。

    
     # before 
     solver = ppsci.solver.Solver(
         model,
         constraint,
         cfg.output_dir,
         optimizer,
         lr_scheduler,
         cfg.TRAIN.epochs,
         cfg.TRAIN.iters_per_epoch,
         save_freq=cfg.TRAIN.save_freq,
         log_freq=cfg.log_freq,
         eval_during_train=True,
         eval_freq=cfg.TRAIN.eval_freq,
         seed=cfg.seed,
         equation=equation,
         geom=geom,
         validator=validator,
         visualizer=visualizer,
         pretrained_model_path=cfg.TRAIN.pretrained_model_path,
         checkpoint_path=cfg.TRAIN.checkpoint_path,
         eval_with_no_grad=cfg.EVAL.eval_with_no_grad,
     )
    
     # after
     solver = ppsci.solver.Solver(
         model,
         constraint,
         optimizer=optimizer,
         equation=equation,
         validator=validator,
         visualizer=visualizer,
         cfg=cfg,
     )

TODO: 文档代码块位置更新

Copy link

paddle-bot bot commented Apr 16, 2024

Thanks for your contribution!

@HydrogenSulfate HydrogenSulfate changed the title [Refine] Remove redundant seed fixing code and logger init code [Refine] Remove redundant seed fixing and logger init code Apr 17, 2024
@HydrogenSulfate HydrogenSulfate changed the title [Refine] Remove redundant seed fixing and logger init code [Refine] Remove redundant code Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant