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

【NOMERGE】Profile load graph time #619

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
for debug update
  • Loading branch information
doombeaker committed Feb 7, 2024
commit 4e7cd9b2aa51045f27e40fb5625cca9d39c1e32a
82 changes: 39 additions & 43 deletions examples/mywarmupmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,59 @@ def __init__(self):
self.groupnorm = nn.GroupNorm(3, 6)
self.layer_norm = nn.LayerNorm([24, 6, 24])

def forward(self, x):
# # Perform operations
# #x = torch.expand_dims(x, dim=1)
# #x = torch.broadcast_dim_like(x, self.weight)
# x = torch.arange(10)
# #x = torch.scalar_mul(x, 0.5)
# #x = torch.scalar_div(x, 2.0)
# x = torch.exp(x)
# #x = torch.broadcast_mul(x, self.weight)
# x = torch.sin(x)
# x = torch.cos(x)
# #x = torch.clip(x, -1, 0)
# #x = torch.cat([x, x], dim=1)
# #x = torch.slice(x, 1, 0, 5)
# #x = torch.cast(x, dtype=torch.float16)
# #x = torch.fused_matmul_bias(x, self.weight, self.bias)
# #x = torch.silu(x)
# x = torch.flatten(x)
# #x = torch.unflatten(x, sizes=[2, 3, 4])
# #x = torch.add_n([x, x])

def forward(self, x, a, b, w):
x = self.conv2d(x)
x = self.groupnorm(x)
#x = torch.broadcast_add(x, self.bias)
x = torch.transpose(x, 1, 2)
x = self.layer_norm(x)
#x = torch.broadcast_matmul(x, x)
x = torch.reshape(x, (2, -1))
x = torch.empty(3, 3)

a = torch.randn(2, 4, 8)
b = torch.randn(2, 8, 3)
x = torch.bmm(a, b)
x = torch.sin(x)
x = torch.cos(x)
tup_list = [[None, None, None], [0, 4, 1],]
x = torch.slice(x, slice_tup_list=tup_list)
x = x.reshape(2, -1, 4)
x = x + a
x = torch.bmm(x, b)
x = torch.softmax(x, dim=1)
x = torch.narrow(x, 1, 0, 2)
#x = torch.gelu(x)
#x = torch.reshape_like(x, self.weight)
x = torch.nn.functional.interpolate(x, scale_factor=2, mode='nearest')
#x = torch.grouped_matmul_bias(x, self.weight, self.bias)
#x = torch.timestep_embedding(x, 4)
#x = torch.fused_multi_head_attention_inference(x, self.weight, self.bias)
#x = torch.fused_glu(x)

x = x*1.0
x = x/1.0
print(f"### x:{x.shape}, a:{a.shape}, b:{b.shape}, w:{w.shape}")
x = torch.flatten(x, start_dim=1)
a = torch.flatten(x, start_dim=1)
print(f"### x:{x.shape}, a:{a.shape}, b:{b.shape}, w:{w.shape}")
x = torch.cat([x,a])
x = torch.clip(x, min=-1, max=1)
x = torch.exp(x)
x = torch.flatten(x, start_dim=0)
tup_list = [[0, 32, 1],]
x = torch.slice(x, slice_tup_list=tup_list)
x = torch._C.unflatten(x, 0, (4, 8))
a_1 = torch.empty(a.shape).cuda()
a = a + a_1
x = torch._C.reshape_like(x, a)
x = torch.cast(x, torch.float16)
print(f"### x:{x.shape} {x.dtype}, a:{a.shape}, b:{b.shape}, w:{w.shape}")
x = torch.narrow(x, 0, 0, 2)
return x
class SimpleGraph(nn.Graph):
def __init__(self, model):
super().__init__()
self.model = model

def build(self, input):
return self.model(input)
if __name__ == "__main__":
def build(self, *input):
return self.model(*input)

def global_warmup():
m = SimpleModule()
m.eval()
m = m.cuda()
a = torch.randn(2, 4, 4).cuda()
b = torch.randn(2, 4, 4).cuda()
x = torch.randn(1,3,28,28).cuda()
w = torch.randn(2,4).cuda()
g = SimpleGraph(m)
y = g(x)
print(y.shape)
y = g(x,a,b,w)
print(y.shape)

if __name__ == "__main__":
global_warmup()
6 changes: 6 additions & 0 deletions judge_op_wanted.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set -e
echo "build simple graph"
python examples/mywarmupmodule.py

echo "====================="
python extract_op_type_name.py