您的位置:首页 > 游戏 > 手游 > 游戏代理商如何赚钱_企业网站有哪些举例_百度热度_网络营销成功的案例及其原因

游戏代理商如何赚钱_企业网站有哪些举例_百度热度_网络营销成功的案例及其原因

2024/12/23 6:30:54 来源:https://blog.csdn.net/chengyq116/article/details/144334027  浏览:    关键词:游戏代理商如何赚钱_企业网站有哪些举例_百度热度_网络营销成功的案例及其原因
游戏代理商如何赚钱_企业网站有哪些举例_百度热度_网络营销成功的案例及其原因

PyTorch 切片运算 {Slice Operator}

  • 1. `[:, -1, :]`
  • 2. `[:, [-1], :]`
  • References

1. [:, -1, :]

https://github.com/karpathy/llama2.c/blob/master/model.py

import torchlogits = torch.arange(1, 16)
print("logits.shape:", logits.shape)
print("logits:\n", logits)logits = logits.view(1, 3, 5)
print("\nlogits.shape:", logits.shape)
print("logits:\n", logits)final_logit_1 = logits[:, -1, :]
print("\nfinal_logit_1.shape:", final_logit_1.shape)
print("final_logit_1:\n", final_logit_1)final_logit_2 = logits[:, -1]
print("\nfinal_logit_2.shape:", final_logit_2.shape)
print("final_logit_2:\n", final_logit_2)final_logit_3 = logits[:, 2, :]
print("\nfinal_logit_3.shape:", final_logit_3.shape)
print("final_logit_3:\n", final_logit_3)final_logit_4 = logits[:, 2]
print("\nfinal_logit_4.shape:", final_logit_4.shape)
print("final_logit_4:\n", final_logit_4)
/home/yongqiang/miniconda3/bin/python /home/yongqiang/llm_work/llama2.c/yongqiang.py 
logits.shape: torch.Size([15])
logits:tensor([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])logits.shape: torch.Size([1, 3, 5])
logits:tensor([[[ 1,  2,  3,  4,  5],[ 6,  7,  8,  9, 10],[11, 12, 13, 14, 15]]])final_logit_1.shape: torch.Size([1, 5])
final_logit_1:tensor([[11, 12, 13, 14, 15]])final_logit_2.shape: torch.Size([1, 5])
final_logit_2:tensor([[11, 12, 13, 14, 15]])final_logit_3.shape: torch.Size([1, 5])
final_logit_3:tensor([[11, 12, 13, 14, 15]])final_logit_4.shape: torch.Size([1, 5])
final_logit_4:tensor([[11, 12, 13, 14, 15]])Process finished with exit code 0

2. [:, [-1], :]

https://github.com/karpathy/llama2.c/blob/master/model.py

import torchlogits = torch.arange(1, 16)
print("logits.shape:", logits.shape)
print("logits:\n", logits)logits = logits.view(1, 3, 5)
print("\nlogits.shape:", logits.shape)
print("logits:\n", logits)final_logit_1 = logits[:, -1, :]
print("\nfinal_logit_1.shape:", final_logit_1.shape)
print("final_logit_1:\n", final_logit_1)final_logit_2 = logits[:, [-1], :]
print("\nfinal_logit_2.shape:", final_logit_2.shape)
print("final_logit_2:\n", final_logit_2)final_logit_3 = logits[:, -1]
print("\nfinal_logit_3.shape:", final_logit_3.shape)
print("final_logit_3:\n", final_logit_3)final_logit_4 = logits[:, [-1]]
print("\nfinal_logit_4.shape:", final_logit_4.shape)
print("final_logit_4:\n", final_logit_4)
/home/yongqiang/miniconda3/bin/python /home/yongqiang/llm_work/llama2.c/yongqiang.py 
logits.shape: torch.Size([15])
logits:tensor([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])logits.shape: torch.Size([1, 3, 5])
logits:tensor([[[ 1,  2,  3,  4,  5],[ 6,  7,  8,  9, 10],[11, 12, 13, 14, 15]]])final_logit_1.shape: torch.Size([1, 5])
final_logit_1:tensor([[11, 12, 13, 14, 15]])final_logit_2.shape: torch.Size([1, 1, 5])
final_logit_2:tensor([[[11, 12, 13, 14, 15]]])final_logit_3.shape: torch.Size([1, 5])
final_logit_3:tensor([[11, 12, 13, 14, 15]])final_logit_4.shape: torch.Size([1, 1, 5])
final_logit_4:tensor([[[11, 12, 13, 14, 15]]])Process finished with exit code 0

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com