Skip to content

debug on KJT issue #2058

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

Closed
wants to merge 1 commit into from
Closed

Conversation

TroyGarden
Copy link
Contributor

Summary:

context

  • In the IR export workflow, the module takes KJTs as input and produces an ExportedProgram of the module
  • KJT actually has a variable length for the values and weights
  • This dynamic nature of KJT needs to be explicitly passed to torch.export

changes

  • add a util function to mark the input KJT's dynamic shape
  • add in the test of how to correctly specify the dynamics shapes for the input KJT

results

  • input KJTs with different value lengths
(Pdb) feature1.values()
tensor([0, 1, 2, 3, 2, 3])
(Pdb) feature2.values()
tensor([0, 1, 2, 3, 2, 3, 4])
  • exported_program can take those input KJTs
(Pdb) ep.module()(feature1)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
(Pdb) ep.module()(feature2)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
  • deserialized module can take those input KJTs
(Pdb) deserialized_model(feature1)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.2593,  0.6758,  1.0010,  0.9052]],
       grad_fn=<SplitWithSizesBackward0>)]
(Pdb) deserialized_model(feature2)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.9359,  0.1123,  0.5834, -0.1357]],
       grad_fn=<SplitWithSizesBackward0>)]

Differential Revision: D57824907

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 29, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D57824907

TroyGarden added a commit to TroyGarden/torchrec that referenced this pull request May 29, 2024
Summary:

# context
* In the IR export workflow, the module takes KJTs as input and produces an `ExportedProgram` of the module
* KJT actually has a variable length for the values and weights
* This dynamic nature of KJT needs to be explicitly passed to torch.export

# changes
* add a util function to mark the input KJT's dynamic shape
* add in the test of how to correctly specify the dynamics shapes for the input KJT

# results
* input KJTs with different value lengths
```
(Pdb) feature1.values()
tensor([0, 1, 2, 3, 2, 3])
(Pdb) feature2.values()
tensor([0, 1, 2, 3, 2, 3, 4])
```
* exported_program can take those input KJTs
```
(Pdb) ep.module()(feature1)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
(Pdb) ep.module()(feature2)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
```
* deserialized module can take those input KJTs
```
(Pdb) deserialized_model(feature1)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.2593,  0.6758,  1.0010,  0.9052]],
       grad_fn=<SplitWithSizesBackward0>)]
(Pdb) deserialized_model(feature2)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.9359,  0.1123,  0.5834, -0.1357]],
       grad_fn=<SplitWithSizesBackward0>)]
```

Differential Revision: D57824907
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D57824907

TroyGarden added a commit to TroyGarden/torchrec that referenced this pull request May 29, 2024
Summary:

# context
* In the IR export workflow, the module takes KJTs as input and produces an `ExportedProgram` of the module
* KJT actually has a variable length for the values and weights
* This dynamic nature of KJT needs to be explicitly passed to torch.export

# changes
* add a util function to mark the input KJT's dynamic shape
* add in the test of how to correctly specify the dynamics shapes for the input KJT

# results
* input KJTs with different value lengths
```
(Pdb) feature1.values()
tensor([0, 1, 2, 3, 2, 3])
(Pdb) feature2.values()
tensor([0, 1, 2, 3, 2, 3, 4])
```
* exported_program can take those input KJTs
```
(Pdb) ep.module()(feature1)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
(Pdb) ep.module()(feature2)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
```
* deserialized module can take those input KJTs
```
(Pdb) deserialized_model(feature1)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.2593,  0.6758,  1.0010,  0.9052]],
       grad_fn=<SplitWithSizesBackward0>)]
(Pdb) deserialized_model(feature2)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.9359,  0.1123,  0.5834, -0.1357]],
       grad_fn=<SplitWithSizesBackward0>)]
```

Differential Revision: D57824907
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D57824907

TroyGarden added a commit to TroyGarden/torchrec that referenced this pull request May 30, 2024
Summary:

# context
* In the IR export workflow, the module takes KJTs as input and produces an `ExportedProgram` of the module
* KJT actually has a variable length for the values and weights
* This dynamic nature of KJT needs to be explicitly passed to torch.export

# changes
* add a util function to mark the input KJT's dynamic shape
* add in the test of how to correctly specify the dynamics shapes for the input KJT

# results
* input KJTs with different value lengths
```
(Pdb) feature1.values()
tensor([0, 1, 2, 3, 2, 3])
(Pdb) feature2.values()
tensor([0, 1, 2, 3, 2, 3, 4])
```
* exported_program can take those input KJTs
```
(Pdb) ep.module()(feature1)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
(Pdb) ep.module()(feature2)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
```
* deserialized module can take those input KJTs
```
(Pdb) deserialized_model(feature1)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.2593,  0.6758,  1.0010,  0.9052]],
       grad_fn=<SplitWithSizesBackward0>)]
(Pdb) deserialized_model(feature2)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.9359,  0.1123,  0.5834, -0.1357]],
       grad_fn=<SplitWithSizesBackward0>)]
```

Differential Revision: D57824907
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D57824907

TroyGarden added a commit to TroyGarden/torchrec that referenced this pull request May 30, 2024
Summary:

# context
* In the IR export workflow, the module takes KJTs as input and produces an `ExportedProgram` of the module
* KJT actually has a variable length for the values and weights
* This dynamic nature of KJT needs to be explicitly passed to torch.export

# changes
* add a util function to mark the input KJT's dynamic shape
* add in the test of how to correctly specify the dynamics shapes for the input KJT

# results
* input KJTs with different value lengths
```
(Pdb) feature1.values()
tensor([0, 1, 2, 3, 2, 3])
(Pdb) feature2.values()
tensor([0, 1, 2, 3, 2, 3, 4])
```
* exported_program can take those input KJTs
```
(Pdb) ep.module()(feature1)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
(Pdb) ep.module()(feature2)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
```
* deserialized module can take those input KJTs
```
(Pdb) deserialized_model(feature1)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.2593,  0.6758,  1.0010,  0.9052]],
       grad_fn=<SplitWithSizesBackward0>)]
(Pdb) deserialized_model(feature2)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.9359,  0.1123,  0.5834, -0.1357]],
       grad_fn=<SplitWithSizesBackward0>)]
```

Differential Revision: D57824907
Summary:

# context
* In the IR export workflow, the module takes KJTs as input and produces an `ExportedProgram` of the module
* KJT actually has a variable length for the values and weights
* This dynamic nature of KJT needs to be explicitly passed to torch.export

# changes
* add a util function to mark the input KJT's dynamic shape
* add in the test of how to correctly specify the dynamics shapes for the input KJT

# results
* input KJTs with different value lengths
```
(Pdb) feature1.values()
tensor([0, 1, 2, 3, 2, 3])
(Pdb) feature2.values()
tensor([0, 1, 2, 3, 2, 3, 4])
```
* exported_program can take those input KJTs
```
(Pdb) ep.module()(feature1)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
(Pdb) ep.module()(feature2)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
```
* deserialized module can take those input KJTs
```
(Pdb) deserialized_model(feature1)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.2593,  0.6758,  1.0010,  0.9052]],
       grad_fn=<SplitWithSizesBackward0>)]
(Pdb) deserialized_model(feature2)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.9359,  0.1123,  0.5834, -0.1357]],
       grad_fn=<SplitWithSizesBackward0>)]
```

Reviewed By: PaulZhang12

Differential Revision: D57824907
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D57824907

PaulZhang12 pushed a commit that referenced this pull request Jun 5, 2024
Summary:
Pull Request resolved: #2058

# context
* In the IR export workflow, the module takes KJTs as input and produces an `ExportedProgram` of the module
* KJT actually has a variable length for the values and weights
* This dynamic nature of KJT needs to be explicitly passed to torch.export

# changes
* add a util function to mark the input KJT's dynamic shape
* add in the test of how to correctly specify the dynamics shapes for the input KJT

# results
* input KJTs with different value lengths
```
(Pdb) feature1.values()
tensor([0, 1, 2, 3, 2, 3])
(Pdb) feature2.values()
tensor([0, 1, 2, 3, 2, 3, 4])
```
* exported_program can take those input KJTs
```
(Pdb) ep.module()(feature1)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
(Pdb) ep.module()(feature2)
[tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16]]), tensor([[-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15],
        [-2.8735e-16, -2.8735e-16, -2.8735e-16, -2.8735e-16, -1.4368e-15,
         -1.4368e-15, -1.4368e-15, -1.4368e-15]])]
```
* deserialized module can take those input KJTs
```
(Pdb) deserialized_model(feature1)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.2593,  0.6758,  1.0010,  0.9052]],
       grad_fn=<SplitWithSizesBackward0>)]
(Pdb) deserialized_model(feature2)
[tensor([[ 0.2630,  0.1473, -0.3691,  0.2261],
        [ 0.0000,  0.0000,  0.0000,  0.0000]],
       grad_fn=<SplitWithSizesBackward0>), tensor([[ 0.2198, -0.1648, -0.0121,  0.1998, -0.0384, -0.2458, -0.6844,  0.8741],
        [ 0.1313,  0.2968, -0.2979, -0.2150, -0.9359,  0.1123,  0.5834, -0.1357]],
       grad_fn=<SplitWithSizesBackward0>)]
```

Reviewed By: PaulZhang12

Differential Revision: D57824907

fbshipit-source-id: 615f602314e6517dba37e83eea5066de5950dc42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants