When writing programs involving matrices or tensors in general, it is desirable to rule out the inconsistency of tensor shapes (i.e., the generalization of matrix sizes) before actual computation. For this purpose, some languages provide dependent types such as Mat m n, and others offer refinement types to track predicates for shapes. Despite the theoretical maturity, however, such methods are often unhandy for continuous software development due to the requirement of proofs for judging type equality or subtyping; even automated proving is often unsuitable due to its unforeseeable time consumption. To remedy this, our study provides an alternative formalization by using staging. Based on the observation that conditions for the shape consistency can be extracted before running the actual tensor computations in many typical cases, we ensure such consistency by assertions evaluated as compile-time computations, not by proofs. Under this formalization, we can verify the consistency virtually statically in the sense that inconsistencies as to tensor shapes will be immediately detected as assertion failures during compile-time computation. Our work achieves a mathematical guarantee that successfully generated code is always consistent with respect to tensor shapes. Furthermore, to vastly lessen the burden of adding shape- or stage-related descriptions, we (1) allow shape-related arguments to be implicit and infer them in a best-effort manner, and (2) offer a non-staged surface language that seemingly resembles ordinary dependently-typed languages and translate its programs into the staged core language. By a prototype implementation, we confirm that our language is expressive enough to verify a number of programs, including several examples offered by ocaml-torch.


翻译:在编写涉及矩阵或一般张量的程序时,希望在真正计算之前排除张量形状(即矩阵大小的推广)的不一致性。为此,某些语言提供了依赖类型(例如 Mat m n),另一些则提供细化类型以跟踪关于形状的谓词。然而,尽管这些方法在理论上已经成熟,但由于需要证明来判定类型相等或子类型关系,它们在持续软件开发中往往不够方便;即便是自动证明,也因其不可预见的时间消耗而常常不适合。为了解决这一问题,我们的研究通过使用阶段化提供了一种替代的形式化方法。基于在许多典型情况下,形状一致性的条件可以在实际张量计算运行之前提取出来的观察,我们通过断言(在编译时计算中进行求值)而非证明来确保这种一致性。在这种形式化下,我们可以在近乎静态的意义上验证一致性,即张量形状的不一致性会在编译时计算过程中立即作为断言失败被检测到。我们的工作实现了数学上的保证:成功生成的代码在张量形状上始终是一致的。此外,为了大幅减轻添加形状或阶段相关描述的负担,我们(1)允许形状相关参数为隐式参数,并以尽力而为的方式进行推断,以及(2)提供一种看似类似普通依赖类型语言的非阶段表面语言,并将其程序翻译到阶段化核心语言中。通过一个原型实现,我们确认我们的语言具有足够的表现力来验证多个程序,包括 ocaml-torch 提供的几个示例。

0
下载
关闭预览

相关内容

大型语言模型系统中提示缺陷的分类学
专知会员服务
8+阅读 · 2025年9月19日
细粒度图像分类的深度学习方法
专知会员服务
43+阅读 · 2021年10月18日
使用 Bert 预训练模型文本分类(内附源码)
数据库开发
102+阅读 · 2019年3月12日
图分类:结合胶囊网络Capsule和图卷积GCN(附代码)
中国人工智能学会
36+阅读 · 2019年2月26日
统计学常用数据类型
论智
19+阅读 · 2018年7月6日
概率图模型体系:HMM、MEMM、CRF
机器学习研究会
30+阅读 · 2018年2月10日
各种相似性度量及Python实现
机器学习算法与Python学习
11+阅读 · 2017年7月6日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Arxiv
0+阅读 · 4月17日
VIP会员
最新内容
综述 | 3D场景图:开放挑战与未来方向
专知会员服务
4+阅读 · 6月22日
21世纪的无人机战争
专知会员服务
4+阅读 · 6月22日
《量子技术的军事任务技术适配与利用》
专知会员服务
4+阅读 · 6月22日
美国从乌克兰无人机战争中学习经验
专知会员服务
7+阅读 · 6月21日
ICML 2026 | 面向视觉语言模型的语义鲁棒性认证
专知会员服务
5+阅读 · 6月21日
相关基金
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员