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

Correct callback initialization method call in Learner class修正 Learner 类中的回调函数初始化方法调用 #119

Open
Reborn14 opened this issue Sep 5, 2024 · 1 comment

Comments

@Reborn14
Copy link

Reborn14 commented Sep 5, 2024

修正 Learner 类中的回调函数初始化方法调用

问题描述

PatchTST_self_supervised/src/learner.py 文件中,Learner 类的 initialize_callbacks 方法中存在一个小错误。当前代码试图调用回调函数的 init_cb 方法,但实际上正确的方法名应该是 init_cb_

当前代码

# in PatchTST_self_supervised/src/learner.py
def initialize_callbacks(self, cbs):
    # ... 其他代码 ...
    
    # 调用所有回调函数的init_cb方法(如果存在)
    self('init_cb')

期望的修改

# in PatchTST_self_supervised/src/learner.py
def initialize_callbacks(self, cbs):
    # ... 其他代码 ...
    
    # 调用所有回调函数的init_cb_方法(如果存在)
    self('init_cb_')

原因

PatchTST_self_supervised/src/callback/tracking.py 文件中,TrackTrainingCB 类定义了 init_cb_ 方法:

def init_cb_(self):
    self.setup()    
    self.initialize_recorder()        
    if hasattr(self.loss_func, 'reduction'):
        self.mean_reduction_ = True if self.loss_func.reduction == 'mean' else False   

为了保持一致性并确保正确调用初始化方法,我们需要在 Learner 类中使用正确的方法名。

影响

这个修改将确保所有回调函数的初始化方法被正确调用,从而保证训练过程中的各项设置和记录功能正常运行。

Correct callback initialization method call in Learner class

Problem Description

There is a minor error in the initialize_callbacks method of the Learner class in the PatchTST_self_supervised/src/learner.py file. The current code attempts to call the init_cb method of the callbacks, but the correct method name should be init_cb_.

Current Code

# in PatchTST_self_supervised/src/learner.py
def initialize_callbacks(self, cbs):
    # ... other code ...
    
    # Call the init_cb method of all callbacks (if it exists)
    self('init_cb')

Expected Change

# in PatchTST_self_supervised/src/learner.py
def initialize_callbacks(self, cbs):
    # ... other code ...
    
    # Call the init_cb_ method of all callbacks (if it exists)
    self('init_cb_')

Reason

In the PatchTST_self_supervised/src/callback/tracking.py file, the TrackTrainingCB class defines the init_cb_ method:

def init_cb_(self):
    self.setup()    
    self.initialize_recorder()        
    if hasattr(self.loss_func, 'reduction'):
        self.mean_reduction_ = True if self.loss_func.reduction == 'mean' else False   

To maintain consistency and ensure the correct initialization method is called, we need to use the correct method name in the Learner class.

Impact

This change will ensure that the initialization methods of all callbacks are correctly called, thus guaranteeing the proper functioning of various settings and recording features during the training process.

@VincentCCandela
Copy link

The code might be useful, but in non-english text format, it is not.

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

No branches or pull requests

2 participants