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

paddle的反向传播疑惑 #70821

Open
ai1361720220000 opened this issue Jan 14, 2025 · 1 comment
Open

paddle的反向传播疑惑 #70821

ai1361720220000 opened this issue Jan 14, 2025 · 1 comment
Labels

Comments

@ai1361720220000
Copy link

ai1361720220000 commented Jan 14, 2025

请提出你的问题 Please ask your question

在使用torch_pruning工程中,想做一些修改适配paddle。发现在反向传播中,有一些变量在paddle中不知道是什么?恳请版忙解答。
比如在split操作的梯度grad_fn中,pytorch是有一个_saved_dim的变量,paddle是什么呢?

`

   def _update_split_index_mapping(self, split_node: Node):
    if split_node.type != ops.OPTYPE.SPLIT:
        return

    if hasattr(split_node.grad_fn, '_saved_dim'): # this only works for Pytorch>=1.12

        # There a issue in some pytorch version, where the _saved_dim is an uninitialized value like 118745347895359
        # So we need to check if the _saved_dim is a valid value (<len(_saved_self_sym_sizes) or a nominal value like 20)
        if hasattr(split_node.grad_fn, '_saved_self_sym_sizes'):
            if split_node.grad_fn._saved_dim<len(split_node.grad_fn._saved_self_sym_sizes) and split_node.grad_fn._saved_dim != 1:
                return
        else:
            THRESHOLD = 20
            if split_node.grad_fn._saved_dim<THRESHOLD and split_node.grad_fn._saved_dim>=0 and split_node.grad_fn._saved_dim != 1:
                return 

`

以及reshape操作的梯度grad_fn中,pytorch有一个_saved_self_sizes变量。

`

def _update_reshape_index_mapping(self, reshape_node: Node):

    # Only Supports 2D/4D tensors
    # TODO: Better support for reshape/view/flatten
    if hasattr(reshape_node.grad_fn, '_saved_self_sizes'): 
        size = reshape_node.grad_fn._saved_self_sizes
        if (len(size)!=1 and len(size)!=4):
            return
    else: # legacy version
        if not self._2d_4d:
            return 

`

@iosmers
Copy link
Contributor

iosmers commented Jan 17, 2025

Paddle的API与Torch API并不保证百分百对齐,具体可能得从实现上分析分析

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants