Skip to content

torch.nn.Transformer cannot be compiled #102331

@yxd886

Description

@yxd886

Issue description

I intended to use torch.nn.Transformer to build my model, and use torch.compile to compile it. But I found that the model is still eager mode even if I used torch.compile

Code example

import torch
device = "cpu"
model = torch.nn.Transformer(nhead=2, num_encoder_layers=2, d_model=6, dim_feedforward=4).to(device)
print(model)
src = torch.rand(2, 4, 6).to(device)
tgt = torch.rand(4, 4, 6).to(device)
compiled_model = torch.compile(model)
out = compiled_model(src, tgt)
print(out)
  • PyTorch or Caffe2: Pytorch
  • PyTorch version: 2.0.0
  • Python version: 3.8

cc @jbschlosser @bhosmer @cpuhrsch @erichan1 @drisspg @ezyang @msaroufim @wconstab @ngimel @bdhirsh @anijain2305

Metadata

Metadata

Assignees

No one assigned

    Labels

    oncall: pt2triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions