From e18f373d59ffd1832d7015f4a29bf4a42a0d1df0 Mon Sep 17 00:00:00 2001 From: sunjiachen111 <1720638369@qq.com> Date: Fri, 5 Sep 2025 14:46:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86torch=5Fcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__pycache__/example_cudacode.cpython-310.pyc | Bin 0 -> 1521 bytes .../example_torchcode.cpython-310.pyc | Bin 0 -> 1570 bytes example/001-example/example_torchcode.py | 13 +++++++++---- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 example/001-example/__pycache__/example_cudacode.cpython-310.pyc create mode 100644 example/001-example/__pycache__/example_torchcode.cpython-310.pyc diff --git a/example/001-example/__pycache__/example_cudacode.cpython-310.pyc b/example/001-example/__pycache__/example_cudacode.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..15afe709affc453571e82ab95a18caf57504ceca GIT binary patch literal 1521 zcma)6O>f&a7$#-emStzn1`KF#1omY$uA3I<4vA|FNU?5*WdYJ&G!L92(zOzOxFpp| zS=vhj^tAub9`hIWQ*_;Fe_^}qB_(Gnu)`>jd_VX;?}uJ8+uCvwjDGq1>a~r~ADU^8 zJ}}?Fl;6R^5W_L@^=`#Dv3v_7*6};c_HAylF1LAy^`2qYXU=b3zxx=m0dp@Ab2&Qg zo%Y{!e23v<G<4|UY8Yn$qfr`1DG$D|5OP0@(lE{$Co`3aaCMg#il;Kl(&=j6 zQieGTsK`?lC0uJM<09qpILuP1$P#?1+oYImsB%K0R1q1S zbC3M$5*V6~SV10=lQ;{{zGua>Ah&DgQIr6)L)1#}fEm?(ZL}m~Z8ZA;O2d^uf&6Dc zTP8uV92bV2klpFht4&|IuUyw8y0`ZP^2|gXxK3~Up}g3{800E5o&dL)rg;JxHgHB& zg1j;1$y${(j?VbFXpYpi(0Q5+sm>k@?mzgtNd`24NsU&5W^7LEw2$8*_dIg9C8%%>0x2*qe~@zl7%3Y`|46Qc~_i#m;yBcg^l3eA*=dk)e;BUURA#vdx%5Y-r5dgpEb}x}&~~!wzu@8|lRVT-+a8^Uk)H#> zk&hYjt+!~28D`d{0~Z6X#wGIYx5!3*7aG4?IX`5K$A|o7h+9ya)@XXlo3JRP@CABf zy|dmUj8x|W(GEk$=n5ZtcGZ>nnhW8;!OEd$ zUk>&bPbC*}@#FF0s0>$uNRC8y%0nd=>r$<&NAS7eTU)`C@nX z-klBI>{M4Qgrn1SDTd(vE0_|V5%dvu@%hJ_RHvH|L%87AL(@9s1DJ9I%LO_`@9+hF z4^M;`fWWg%PC_FBtZQ2M7+TESb9 zWGs(0J)-n^9>lfABq2W0s9R0-LLS4D((<_lTA>}A@_z}0?7`xI+ily(yg}79_s_p& zwrQ@SSWb1XT|Z_*2kH+^Pu4Bx->4h(x+6{Qm6fJd53+%14R|XOQwLK5XIAGk*L`IA W$H60PWBXI9YhnG_FnfRBbp8QN+Mq`O literal 0 HcmV?d00001 diff --git a/example/001-example/__pycache__/example_torchcode.cpython-310.pyc b/example/001-example/__pycache__/example_torchcode.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..296475d9ee39108443e8a866c1295cad3f8ec076 GIT binary patch literal 1570 zcmZux&2HQ_5GEx`E6clX<3pNL%c4LL0m&lmC4dnWDGVei&?bwxz6c8tipbrSp_Miy zH~zu)6a#q;`{-B5TjZ*1PkDu&Iz!3pt?L0eeFnO5%M<*n*@90 zISlgxm?V;xByDFp_fn6NmqdEfKPS>x-jV;oPnl$CAcHiNVcL^D8J&|fl3Ox{c}vm* zl5BqgUF21ce3Q@?l6ekHk(5f3dXlET^b`aAY{EX036)F+=Y6mds_+ObAfGS^HqKcZ zeIyL*fR(rj{-~uY&z{B{=%AP{O2y~6#qBJ!e4+HD)^o!%{zmXnbXLi#36E7Vo!P{1m{H|K zqg{;|yQ0mO5P6vyBg7T?C)?i}9~!02`1QefbehjHJs;`%Nafay7pHbsSDpCt_~qzu z9}@Bc3@I~KCmH5w{N%|`kFVF=ESxVn+#N1Xbq~x&Fbvw?p%3WUj!X4$9SS{ZLappl zS2+fGO}NH4`!LJ{V3u4^ND(=LB>hD}@>lc{F+#Jaln_@3tlsFlR`bm2;)Ktar7ad^ zk-K{FNnMupv6B4l>HllFR`RQ!n!UAzYESq>7ufJmRhe2Rd;GTwip{MPc|GA~mMs*2 z_%^foOqk+KJ>mskK|CbGc&+V?3-*@!P2GF^wFA<%?&HGF?$Uk(x8xCbms)TxAX*48 zn*cQUomps6i(w^9V^=pJ+=EQ%J_<~$a+!E~0D|5{_Vt?G!wWs=hT}|2yxmrIJNC{7 zZDqSN=qkW#1qcPa#zH_lElXVYg?P8j%I>5mgsgMe_KV6oxO5J+dDi#Q-k?KmuF6t~ z4R3bPFLcQ@2;#*c+9JZ}eg9kLcE6zW1%6EhA}R-IO#qx5lwqWZGV56%Fh*8n3i#3i zY+5Q)qu@cO%qW zCHSh<4!=Qb;skfJ*<Pj@}`4Wo=kUZ4F7NIiCF literal 0 HcmV?d00001 diff --git a/example/001-example/example_torchcode.py b/example/001-example/example_torchcode.py index eb7aac8..aac9859 100644 --- a/example/001-example/example_torchcode.py +++ b/example/001-example/example_torchcode.py @@ -5,23 +5,28 @@ class Model(nn.Module): """ Simple model that performs a ReLU activation. """ - def __init__(self): + def __init__(self, dim: int, output_dim: int): super(Model, self).__init__() + self.weight = nn.Parameter(torch.randn(dim, output_dim)) def forward(self, x: torch.Tensor) -> torch.Tensor: """ - Applies ReLU activation to the input tensor. + Performs matrix multiplication followed by ReLU activation. Args: - x (torch.Tensor): Input tensor of any shape. + x (torch.Tensor): Input tensor of shape (batch_size, input_dim). Returns: - torch.Tensor: Output tensor with ReLU applied, same shape as input. + torch.Tensor: Output tensor with shape (batch_size, output_dim), with ReLU applied after matrix multiplication. """ + # Perform matrix multiplication + x = torch.matmul(x, self.weight) + # Apply ReLU activation return torch.relu(x) batch_size = 16 dim = 16384 +output_dim = 1024 def get_inputs(): x = torch.randn(batch_size, dim) -- Gitee From 305966e50cb920f7f1418b9d3709461aa7798151 Mon Sep 17 00:00:00 2001 From: sunjiachen111 <1720638369@qq.com> Date: Thu, 11 Sep 2025 16:00:05 +0800 Subject: [PATCH 2/2] 111 --- example/001-example/prompt.txt | 4 ++++ example/001-example/run_code.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/example/001-example/prompt.txt b/example/001-example/prompt.txt index 2fecbf3..34123f2 100644 --- a/example/001-example/prompt.txt +++ b/example/001-example/prompt.txt @@ -56,6 +56,10 @@ def get_init_inputs(): # randomly generate tensors required for initialization based on the model architecture return [] ``` + + + + You are given the following architecture: diff --git a/example/001-example/run_code.py b/example/001-example/run_code.py index a18a7cd..035c9d6 100644 --- a/example/001-example/run_code.py +++ b/example/001-example/run_code.py @@ -7,6 +7,8 @@ import time from example_torchcode import Model,get_inputs,get_init_inputs from example_cudacode import ModelNew + + def run_benchmark(): # 检查 CUDA 是否可用 if not torch.cuda.is_available(): @@ -43,7 +45,7 @@ def run_benchmark(): print("❌ 精度不一致!") print("\n-------------------- 性能加速比测试 --------------------") - num_iterations = 100 + num_iterations = 1000 # PyTorch 模型计时 torch.cuda.synchronize() -- Gitee