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

Ltac2: use preterm in exact / eexact #18157

Merged
merged 1 commit into from Nov 18, 2023

Conversation

SkySkimmer
Copy link
Contributor

@SkySkimmer SkySkimmer commented Oct 13, 2023

Fix #12827

The implementation uses a generalization of Constr.pretype which takes flags (an opaque type) and a typing constraint.

Changing refine is left to the future as the notation takes a tactic thunk at constr type so would be backwards incompatible.

Overlays:

@SkySkimmer SkySkimmer added the request: full CI Use this label when you want your next push to trigger a full CI. label Oct 13, 2023
@SkySkimmer SkySkimmer requested a review from a team as a code owner October 13, 2023 16:00
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label Oct 13, 2023
@SkySkimmer
Copy link
Contributor Author

@coqbot bench

Copy link
Member

@JasonGross JasonGross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Should we also add Constr.Preterm.of_constr (c : constr) : preterm := preterm:($c). (this works, right?), either in this or another PR, so it's easier to see how to convert from constr to preterm? (I guess Constr.to_preterm would also be a fine name?)

@SkySkimmer
Copy link
Contributor Author

It works but I'm not sure what the point would be

@JasonGross
Copy link
Member

Yeah, I guess I don't have a concrete use-case in mind at the moment, and was thinking more about completeness of API. I'll retract my suggestion until/unless I have a concrete use-case in mind

(Constr.Pretype.OfType (Control.goal()))
c
in
Control.refine (fun _ => c)).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have a refine_nocheck too

@coqbot-app
Copy link
Contributor

coqbot-app bot commented Oct 14, 2023

🏁 Bench results:

┌──────────────────────────────┬─────────────────────────┬───────────────────────────────────────┬───────────────────────────────────────┬─────────────────────────┐
│                              │      user time [s]      │              CPU cycles               │           CPU instructions            │  max resident mem [KB]  │
│                              │                         │                                       │                                       │                         │
│         package_name         │   NEW      OLD    PDIFF │      NEW             OLD        PDIFF │      NEW             OLD        PDIFF │   NEW      OLD    PDIFF │
├──────────────────────────────┼─────────────────────────┼───────────────────────────────────────┼───────────────────────────────────────┼─────────────────────────┤
│                coq-equations │   11.17    11.31  -1.24 │    48549390396     48553499962  -0.01 │    76587594213     76595032144  -0.01 │  416936   416840   0.02 │
│                     coq-core │  115.51   116.93  -1.21 │   480975068173    471320049663   2.05 │   493464483926    493372062701   0.02 │  378064   367736   2.81 │
│     coq-metacoq-translations │   18.24    18.38  -0.76 │    81617454371     81607618540   0.01 │   131706304550    131637398165   0.05 │  902040   899792   0.25 │
│                 coq-coqprime │   48.14    48.50  -0.74 │   216950887762    218577621065  -0.74 │   329575403686    329468232165   0.03 │  780752   780628   0.02 │
│           coq-mathcomp-field │  215.89   217.30  -0.65 │   984136000183    989998297140  -0.59 │  1750974353681   1750957482195   0.00 │ 1375716  1374364   0.10 │
│                    coq-verdi │   49.78    50.09  -0.62 │   225597653497    226867145638  -0.56 │   339102119651    339256789627  -0.05 │  526912   527080  -0.03 │
│        coq-mathcomp-solvable │  145.22   146.10  -0.60 │   662105218699    666514686721  -0.66 │  1058168076054   1058217838443  -0.00 │  929596   929552   0.00 │
│       coq-mathcomp-ssreflect │  183.86   184.93  -0.58 │   840488166355    845040871149  -0.54 │  1478169061695   1478072082702   0.01 │ 1288516  1286736   0.14 │
│                      coq-vst │  855.64   859.65  -0.47 │  3888744849119   3908888915218  -0.52 │  6382155499912   6382240687107  -0.00 │ 1941588  1941772  -0.01 │
│                  coq-unimath │ 1647.70  1655.16  -0.45 │  7507045141175   7541347698032  -0.45 │ 14032852989601  14032983245695  -0.00 │ 1321520  1323324  -0.14 │
│          coq-category-theory │  752.40   755.14  -0.36 │  3434587450833   3446817402180  -0.35 │  5870117513304   5869818286938   0.01 │  879568   880360  -0.09 │
│                coq-perennial │ 6450.89  6469.26  -0.28 │ 29420988921634  29499810049888  -0.27 │ 48938317558092  48923269861583   0.03 │ 2204880  2205340  -0.02 │
│        coq-engine-bench-lite │  158.93   159.36  -0.27 │   682388269126    684078075338  -0.25 │  1272623269043   1270846051186   0.14 │ 1321208  1320904   0.02 │
│                 coq-rewriter │  375.61   376.48  -0.23 │  1711167471847   1715719858304  -0.27 │  2781656901776   2781019520925   0.02 │ 1280824  1287020  -0.48 │
│                   coq-stdlib │  370.82   371.61  -0.21 │  1577572241011   1576246036051   0.08 │  1388829504894   1388949081582  -0.01 │  757756   756036   0.23 │
│                  coq-bignums │   29.10    29.16  -0.21 │   132803127758    132607582933   0.15 │   189144139095    189131103667   0.01 │  488428   490552  -0.43 │
│ coq-fiat-crypto-with-bedrock │ 6447.52  6458.86  -0.18 │ 29302585172722  29355689265806  -0.18 │ 53606501713806  53599327687808   0.01 │ 2421680  2419808   0.08 │
│       coq-mathcomp-odd-order │  876.58   878.03  -0.17 │  4008653666665   4015644813430  -0.17 │  6741768404921   6741815936435  -0.00 │ 1630548  1630456   0.01 │
│               coq-coquelicot │   38.64    38.70  -0.16 │   172867681710    173557667347  -0.40 │   238150076858    238148706698   0.00 │  794180   794308  -0.02 │
│                coq-fourcolor │ 1521.47  1523.63  -0.14 │  6941813396078   6950185181360  -0.12 │ 12485953970032  12486335501787  -0.00 │ 2060672  2062776  -0.10 │
│         coq-mathcomp-algebra │  474.57   475.17  -0.13 │  2162661755543   2165818181113  -0.15 │  3979973526317   3980060500470  -0.00 │ 1423816  1426136  -0.16 │
│             coq-fiat-parsers │  330.45   330.78  -0.10 │  1485588530869   1487862710781  -0.15 │  2456287223733   2456713288755  -0.02 │ 2436576  2437268  -0.03 │
│  coq-rewriter-perf-SuperFast │  750.03   750.41  -0.05 │  3407445466516   3407865802083  -0.01 │  5768190820447   5769538124474  -0.02 │ 1367880  1368556  -0.05 │
│               coq-verdi-raft │  604.42   604.62  -0.03 │  2757331759060   2758232006604  -0.03 │  4211488730847   4211886364166  -0.01 │  819840   819320   0.06 │
│                 coq-compcert │  283.87   283.96  -0.03 │  1286673052794   1289247166027  -0.20 │  1959912192503   1960429053741  -0.03 │ 1142724  1144448  -0.15 │
│        coq-mathcomp-fingroup │   38.63    38.62   0.03 │   176315736589    175857897012   0.26 │   265453895368    265560622504  -0.04 │  559684   559640   0.01 │
│                     coq-hott │  157.63   157.56   0.04 │   710315755461    711044124839  -0.10 │  1115290994642   1115519930564  -0.02 │  592908   592996  -0.01 │
│                coq-fiat-core │   60.05    59.97   0.13 │   259496905264    259569030783  -0.03 │   379812895120    379837394939  -0.01 │  495056   493172   0.38 │
│                  coq-coqutil │   41.38    41.30   0.19 │   184670771904    183751081384   0.50 │   264403191578    264436943015  -0.01 │  561724   561404   0.06 │
│                     coq-corn │  804.69   803.07   0.20 │  3665610089844   3656076171151   0.26 │  5625264432587   5625524831639  -0.00 │  779884   776780   0.40 │
│         coq-metacoq-template │  165.44   165.10   0.21 │   738894820132    739013314302  -0.02 │  1156021533983   1156358616500  -0.03 │ 1277520  1277544  -0.00 │
│       coq-mathcomp-character │  135.93   135.61   0.24 │   619670141118    618248642326   0.23 │  1001368315091   1001302064098   0.01 │ 1217208  1217116   0.01 │
│   coq-performance-tests-lite │  730.10   727.73   0.33 │  3306834245137   3296388809682   0.32 │  5787406787026   5786049365035   0.02 │ 1690244  1690620  -0.02 │
│            coq-iris-examples │  493.76   492.07   0.34 │  2241184449003   2235247487244   0.27 │  3386465500040   3386496157108  -0.00 │ 1080844  1077568   0.30 │
│             coq-math-classes │   88.26    87.90   0.41 │   398738341766    398163511428   0.14 │   553787652187    553272910453   0.09 │  523016   523532  -0.10 │
│                 coq-bedrock2 │  357.79   356.00   0.50 │  1633998988191   1625895223268   0.50 │  3161765419199   3161475331431   0.01 │  876540   872960   0.41 │
│                    coq-color │  236.55   235.19   0.58 │  1069634941469   1064075680945   0.52 │  1542411057277   1542510073893  -0.01 │ 1135044  1130928   0.36 │
└──────────────────────────────┴─────────────────────────┴───────────────────────────────────────┴───────────────────────────────────────┴─────────────────────────┘

INFO: failed to install
coq-metacoq-pcuic

coq-metacoq-safechecker (dependency coq-metacoq-pcuic failed)
coq-metacoq-erasure (dependency coq-metacoq-pcuic failed)

🐢 Top 25 slow downs
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                 TOP 25 SLOW DOWNS                                                                  │
│                                                                                                                                                    │
│   OLD       NEW      DIFF    %DIFF    Ln                      FILE                                                                                 │
├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ 159.8330  162.5840  2.7510    1.72%   233  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/deps/riscv-coq/src/riscv/Proofs/DecodeByExtension.v.html │
│  22.5260   23.5440  1.0180    4.52%   660  coq-perennial/src/program_proof/vrsm/replica/roapply_proof.v.html                                       │
│  11.5640   12.4960  0.9320    8.06%   462  coq-perennial/src/program_proof/simple/write.v.html                                                     │
│  54.5520   55.2410  0.6890    1.26%   609  coq-bedrock2/bedrock2/src/bedrock2Examples/lightbulb.v.html                                             │
│  34.0800   34.6760  0.5960    1.75%   522  coq-perennial/src/program_proof/txn/twophase_refinement_proof.v.html                                    │
│  62.5440   63.1210  0.5770    0.92%   139  coq-fiat-parsers/src/Parsers/Refinement/SharpenedJSON.v.html                                            │
│  17.1090   17.5110  0.4020    2.35%    32  coq-performance-tests-lite/src/pattern.v.html                                                           │
│  32.5230   32.9190  0.3960    1.22%    12  coq-fourcolor/theories/job323to383.v.html                                                               │
│   3.2680    3.6380  0.3700   11.32%   252  coq-perennial/src/program_proof/simple/iread.v.html                                                     │
│  29.7340   30.0610  0.3270    1.10%   912  coq-perennial/src/program_proof/vrsm/reconfig/proof.v.html                                              │
│   4.3280    4.6500  0.3220    7.44%     5  coq-fiat-crypto-with-bedrock/src/Assembly/Parse/Examples/fiat_p256_mul_optimised_seed4.v.html           │
│  27.4330   27.7540  0.3210    1.17%    12  coq-fourcolor/theories/job279to282.v.html                                                               │
│  90.8810   91.1790  0.2980    0.33%   103  coq-fiat-crypto-with-bedrock/src/Arithmetic/BarrettReduction.v.html                                     │
│  33.9620   34.2420  0.2800    0.82%    12  coq-fourcolor/theories/job254to270.v.html                                                               │
│   3.2320    3.4860  0.2540    7.86%    32  coq-performance-tests-lite/src/n_polymorphic_universes.v.html                                           │
│   1.0770    1.3250  0.2480   23.03%  1677  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/RupicolaCrypto/ChaCha20.v.html                         │
│  22.3510   22.5930  0.2420    1.08%    12  coq-fourcolor/theories/job283to286.v.html                                                               │
│  39.1310   39.3590  0.2280    0.58%    85  coq-fiat-crypto-with-bedrock/src/Curves/Montgomery/AffineProofs.v.html                                  │
│  20.3710   20.5980  0.2270    1.11%    12  coq-fourcolor/theories/job311to314.v.html                                                               │
│  44.1490   44.3580  0.2090    0.47%   558  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/bedrock2/src/bedrock2Examples/insertionsort.v.html       │
│  28.9400   29.1450  0.2050    0.71%    12  coq-fourcolor/theories/job611to617.v.html                                                               │
│  23.3510   23.5550  0.2040    0.87%    12  coq-fourcolor/theories/job542to545.v.html                                                               │
│  33.7670   33.9690  0.2020    0.60%   548  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/compiler/src/compiler/MMIO.v.html                        │
│   2.1700    2.3710  0.2010    9.26%  1363  coq-perennial/src/program_proof/buf/buf_proof.v.html                                                    │
│   0.1270    0.3210  0.1940  152.76%   167  coq-fiat-crypto-with-bedrock/src/PushButtonSynthesis/FancyMontgomeryReduction.v.html                    │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
🐇 Top 25 speed ups
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                TOP 25 SPEED UPS                                                                │
│                                                                                                                                                │
│   OLD       NEW      DIFF     %DIFF    Ln                     FILE                                                                             │
├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ 112.3530  111.5240  -0.8290   -0.74%    48  coq-fiat-crypto-with-bedrock/src/Curves/Weierstrass/AffineProofs.v.html                            │
│  43.1860   42.5950  -0.5910   -1.37%   236  coq-rewriter/src/Rewriter/Rewriter/Examples/PerfTesting/LiftLetsMap.v.html                         │
│  42.4810   41.9090  -0.5720   -1.35%   827  coq-vst/veric/binop_lemmas4.v.html                                                                 │
│  65.2320   64.6740  -0.5580   -0.86%   361  coq-perennial/src/program_proof/buf/buf_proof.v.html                                               │
│   2.8080    2.4020  -0.4060  -14.46%   736  coq-stdlib/Reals/Cauchy/ConstructiveCauchyReals.v.html                                             │
│  39.9090   39.5030  -0.4060   -1.02%   835  coq-fiat-crypto-with-bedrock/src/Fancy/Compiler.v.html                                             │
│   9.2030    8.8220  -0.3810   -4.14%    24  coq-perennial/src/program_proof/txn/twophase_refinement_thm.v.html                                 │
│  27.0100   26.6390  -0.3710   -1.37%    68  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/deps/riscv-coq/src/riscv/Proofs/VerifyDecode.v.html │
│  27.7820   27.4380  -0.3440   -1.24%    12  coq-fourcolor/theories/job618to622.v.html                                                          │
│  21.8170   21.4800  -0.3370   -1.54%    12  coq-fourcolor/theories/job490to494.v.html                                                          │
│  17.6940   17.3730  -0.3210   -1.81%  3158  coq-fiat-crypto-with-bedrock/src/Assembly/WithBedrock/Proofs.v.html                                │
│  31.8510   31.5310  -0.3200   -1.00%    12  coq-fourcolor/theories/job107to164.v.html                                                          │
│ 143.6780  143.3620  -0.3160   -0.22%  1190  coq-unimath/UniMath/CategoryTheory/GrothendieckConstruction/IsPullback.v.html                      │
│  29.2430   28.9350  -0.3080   -1.05%    12  coq-fourcolor/theories/job531to534.v.html                                                          │
│  60.4180   60.1110  -0.3070   -0.51%    27  coq-fiat-crypto-with-bedrock/src/Rewriter/Passes/ToFancyWithCasts.v.html                           │
│  20.9250   20.6180  -0.3070   -1.47%    12  coq-fourcolor/theories/job207to214.v.html                                                          │
│  42.4210   42.1150  -0.3060   -0.72%   224  coq-performance-tests-lite/PerformanceExperiments/rewrite_lift_lets_map.v.html                     │
│  14.2900   13.9870  -0.3030   -2.12%  3090  coq-fiat-crypto-with-bedrock/src/Assembly/WithBedrock/Proofs.v.html                                │
│  27.4910   27.2020  -0.2890   -1.05%   823  coq-perennial/src/program_proof/aof/proof.v.html                                                   │
│  34.4980   34.2200  -0.2780   -0.81%    97  coq-vst/veric/binop_lemmas5.v.html                                                                 │
│  26.5990   26.3320  -0.2670   -1.00%  2293  coq-perennial/src/goose_lang/logical_reln_fund.v.html                                              │
│  18.4140   18.1510  -0.2630   -1.43%    12  coq-fourcolor/theories/job235to238.v.html                                                          │
│  52.9840   52.7350  -0.2490   -0.47%   915  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/X25519/GarageDoor.v.html                          │
│  13.2700   13.0260  -0.2440   -1.84%   187  coq-perennial/src/goose_lang/interpreter/disk_interpreter.v.html                                   │
│  22.4170   22.1800  -0.2370   -1.06%    12  coq-fourcolor/theories/job546to549.v.html                                                          │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

@SkySkimmer
Copy link
Contributor Author

┌─ The following actions failed
│ ⬇ fetch coq-metacoq-pcuic dev

ie spurious network issue

I don't think metacoq uses ltac2 much so no point rerunning a bench

@SkySkimmer
Copy link
Contributor Author

@coqbot ci minimize ci-neural_net_interp

@coqbot-app
Copy link
Contributor

coqbot-app bot commented Oct 14, 2023

I am now running minimization at commit d132302 on requested target ci-neural_net_interp. I'll come back to you with the results once it's done.

@coqbot-app
Copy link
Contributor

coqbot-app bot commented Oct 14, 2023

Minimized File /github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp/theories/TransformerLens/HookedTransformer.v (from ci-neural_net_interp) (full log on GitHub Actions)

We are collecting data on the user experience of the Coq Bug Minimizer.
If you haven't already filled the survey for this PR, please fill out our short survey!

Partially Minimized Coq File (could not inline Ltac2.Notations)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "+implicit-core-hint-db,+implicits-in-term,+non-reversible-notation,+deprecated-intros-until-0,+deprecated-focus,+unused-intro-pattern,+variable-collision,+unexpected-implicit-declaration,+omega-is-deprecated,+deprecated-instantiate-syntax,+non-recursive,+undeclared-scope,+deprecated-hint-rewrite-without-locality,+deprecated-hint-without-locality,+deprecated-instance-without-locality,+deprecated-typeclasses-transparency-without-locality,-ltac2-missing-notation-var,unsupported-attributes" "-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp/theories" "NeuralNetInterp" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-top" "NeuralNetInterp.TransformerLens.HookedTransformer") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 473 lines to 51 lines, then from 64 lines to 441 lines, then from 445 lines to 322 lines, then from 335 lines to 1735 lines, then from 1740 lines to 476 lines, then from 489 lines to 648 lines, then from 653 lines to 476 lines, then from 489 lines to 788 lines, then from 793 lines to 467 lines, then from 480 lines to 1012 lines, then from 1017 lines to 469 lines, then from 482 lines to 847 lines, then from 852 lines to 477 lines, then from 490 lines to 718 lines, then from 723 lines to 501 lines, then from 514 lines to 548 lines, then from 553 lines to 512 lines, then from 525 lines to 559 lines, then from 564 lines to 513 lines, then from 526 lines to 560 lines, then from 565 lines to 519 lines, then from 532 lines to 637 lines, then from 642 lines to 522 lines, then from 535 lines to 624 lines, then from 629 lines to 527 lines, then from 540 lines to 609 lines, then from 614 lines to 539 lines, then from 552 lines to 630 lines, then from 635 lines to 552 lines, then from 565 lines to 617 lines, then from 622 lines to 568 lines, then from 581 lines to 1192 lines, then from 1198 lines to 677 lines, then from 691 lines to 757 lines, then from 763 lines to 681 lines, then from 687 lines to 682 lines *)
(* coqc version 8.19+alpha compiled with OCaml 4.09.0
   coqtop version 8b9980c1a092:/builds/coq/coq/_build/default,(HEAD detached at 2564ef3) (2564ef398cf18455f1f1b63024e337c08cfbab26)
   Modules that could not be inlined: Ltac2.Notations
   Expected coqc runtime on this file: 0.662 sec *)
Require Ltac2.Constr.
Require Ltac2.Notations.
Require Coq.Array.PArray.

Module Export Printf.

Import Ltac2.Message.

Ltac2 printf fmt := Format.kfprintf print fmt.
Module Export List.

Import Ltac2.Init.

Ltac2 rec length (ls : 'a list) :=
  match ls with
  | [] => 0
  | _ :: xs => Int.add 1 (length xs)
  end.

Ltac2 rec append ls1 ls2 :=
  match ls1 with
  | [] => ls2
  | x :: xs => x :: append xs ls2
  end.

Ltac2 rec map (f : 'a -> 'b) (ls : 'a list) :=
  match ls with
  | [] => []
  | l :: ls => f l :: map f ls
  end.

Ltac2 rec firstn (n : int) (ls : 'a list) :=
  Control.assert_valid_argument "List.firstn" (Int.ge n 0);
  match Int.equal n 0 with
  | true => []
  | false
    => match ls with
       | [] => Control.throw_out_of_bounds "List.firstn"
       | x :: xs
         => x :: firstn (Int.sub n 1) xs
       end
  end.

Ltac2 rec seq (start : int) (step : int) (last : int) :=
  match Int.lt (Int.sub last start) step with
  | true
    => []
  | false
    => start :: seq (Int.add start step) step last
  end.

Ltac2 init (len : int) (f : int -> 'a) :=
  Control.assert_valid_argument "List.init" (Int.ge len 0);
  map f (seq 0 1 len).

Ltac2 repeat (x : 'a) (n : 'int) :=
  init n (fun _ => x).

Ltac2 rec merge (cmp : 'a -> 'a -> int) (l1 : 'a list) (l2 : 'b list) :=
  let rec merge_aux l2 :=
      match l1 with
      | [] => l2
      | a1 :: l1'
        => match l2 with
           | [] => l1
           | a2 :: l2'
             => match Int.le (cmp a1 a2) 0 with
                | true => a1 :: merge cmp l1' l2
                | false => a2 :: merge_aux l2'
                end
           end
      end in
  merge_aux l2.

Ltac2 rec merge_list_to_stack cmp stack l :=
  match stack with
  | [] => [Some l]
  | l' :: stack'
    => match l' with
       | None => Some l :: stack'
       | Some l'
         => None :: merge_list_to_stack cmp stack' (merge cmp l' l)
       end
  end.

Ltac2 rec merge_stack cmp stack :=
  match stack with
  | [] => []
  | l :: stack'
    => match l with
       | None => merge_stack cmp stack'
       | Some l => merge cmp l (merge_stack cmp stack')
       end
  end.

Ltac2 rec iter_merge cmp stack l :=
  match l with
  | [] => merge_stack cmp stack
  | a::l' => iter_merge cmp (merge_list_to_stack cmp stack [a]) l'
  end.

Ltac2 sort cmp l := iter_merge cmp [] l.

Ltac2 sort_uniq (cmp : 'a -> 'a -> int) (l : 'a list) :=
  let rec uniq l :=
      match l with
      | [] => []
      | x1 :: xs
        => match xs with
           | [] => x1 :: xs
           | x2 :: _
             => match Int.equal (cmp x1 x2) 0 with
                | true => uniq xs
                | false => x1 :: uniq xs
                end
           end
      end in
  uniq (sort cmp l).

End List.
Module Ltac2_DOT_Ltac2_WRAPPED.
Module Export Ltac2.

Export Ltac2.Init.

End Ltac2.

End Ltac2_DOT_Ltac2_WRAPPED.
Module Export Ltac2.
Module Ltac2.
Include Ltac2_DOT_Ltac2_WRAPPED.Ltac2.
End Ltac2.
Module Export Constr.
Import Ltac2.Ltac2.

Module Export Unsafe.
  Export Ltac2.Constr.Unsafe.
  Ltac2 rec kind_nocast (c : constr)
    := let k := kind c in
       match k with
       | Cast c _ _ => kind_nocast c
       | _ => k
       end.
End Unsafe.

End Constr.
Module Export MakeAbbreviations.
Import Ltac2.Ltac2.

Ltac2 mkApp (f : constr) (args : constr list) :=
  make (App f (Array.of_list args)).
Ltac2 mkLambda b (body : constr) :=
  make (Lambda b body).
Ltac2 mkRel (i : int) :=
  make (Rel i).
Ltac2 mkVar (i : ident) :=
  make (Var i).

End MakeAbbreviations.
Export Ltac2.Notations.

Ltac2 Notation "eval" "cbv" s(strategy) "in" c(tactic(6)) :=
  Std.eval_cbv s c.

Ltac2 Notation "eval" "cbn" s(strategy) "in" c(tactic(6)) :=
  Std.eval_cbn s c.

Reserved Infix "::'" (at level 59, left associativity).
Reserved Infix "++'" (at level 59, left associativity).
Reserved Infix "+'" (at level 48, left associativity).
Reserved Notation "√ x" (at level 5, right associativity, format "√ x").
Module Export Nat.
Fixpoint radd (n m : nat) {struct m} : nat.
exact (match m with
     | 0 => n
     | S p => S (radd n p)
     end).
Defined.
  Infix "+'" := radd : nat_scope.
Import Coq.ZArith.ZArith.
Class pointed T := point : T.
#[export] Instance default_Z : pointed Z.
Admitted.
Import Coq.Strings.String.
Definition with_default (name : string) {A} (x : A) := A.
#[global] Arguments with_default _ {_} _, _ _ _.
Existing Class with_default.
Ltac fill_default _ :=
  lazymatch goal with
  | [ |- @with_default ?name ?A ?x ]
    => match goal with
       | [ H : @with_default ?name' ?A' _ |- _ ] => constr_eq A A'; constr_eq name name'; fail 1
       | _ => exact x
       end
  end.
#[global] Hint Extern 0 (with_default _ _) => fill_default () : typeclass_instances.

Module Export NeuralNetInterp_DOT_Util_DOT_Arith_DOT_Classes_WRAPPED.
Module Export Classes.
Class has_eqb A := eqb : A -> A -> bool.
Class has_add_with A B C := add : A -> B -> C.
Notation has_add A := (has_add_with A A A).
Class has_sub_with A B C := sub : A -> B -> C.
Notation has_sub A := (has_sub_with A A A).
Class has_mul_with A B C := mul : A -> B -> C.
Notation has_mul A := (has_mul_with A A A).
Class has_zero A := zero : A.
Class has_one A := one : A.
Class has_max A := max : A -> A -> A.
Class has_sqrt A := sqrt : A -> A.
Class has_div_by A B C := div : A -> B -> C.
Notation has_div A := (has_div_by A A A).
Class has_exp_to A B := exp : A -> B.
Notation has_exp A := (has_exp_to A A).
Class has_coer A B := coer : A -> B.
Notation "√ x" := (sqrt x) : core_scope.

End Classes.
Module Export Arith.
Module Export Classes.
Include NeuralNetInterp_DOT_Util_DOT_Arith_DOT_Classes_WRAPPED.Classes.
#[export] Instance bool_has_eqb : has_eqb bool.
Admitted.
#[export] Instance bool_has_zero : has_zero bool.
Admitted.
#[export] Instance bool_has_one : has_one bool.
Admitted.
Coercion Z.of_N : N >-> Z.
 Coercion Uint63.of_Z : Z >-> Uint63.int.
Import Coq.Numbers.Cyclic.Int63.Uint63.

Module Import Reduction.
Definition sum {A} {zeroA : has_zero A} {addA : has_add A} (start : int) (stop : int) (step : int) (f : int -> A) : A.
Admitted.
Module NeuralNetInterp_DOT_Util_DOT_PArray_WRAPPED.
Module Export PArray.
Open Scope uint63_scope.

End PArray.

End NeuralNetInterp_DOT_Util_DOT_PArray_WRAPPED.
Module Export NeuralNetInterp.
Module Export Util.
Module PArray.
Include NeuralNetInterp_DOT_Util_DOT_PArray_WRAPPED.PArray.
End PArray.
Module Export Tensor.
Import Coq.Lists.List.
Import ListNotations.

Definition Rank := nat.

Module Type IndexType.
  Parameter t : Type.
End IndexType.

Module Type ExtendedIndexType.
  Include IndexType.
End ExtendedIndexType.

Module Export IndexGen.
  Module Make (IndexType : IndexType).
    Notation IndexType := IndexType.t.

    Fixpoint t (r : Rank) : Type
      := match r with
         | O => unit
         | S r => t r * IndexType.t
         end.
    Notation Index := t.
Definition nil : t 0.
Admitted.
    Definition snoc {r} (s : t r) x : t (S r) := (s, x).
    Module Import IndexNotations0.
      Declare Scope index_scope.
      Delimit Scope index_scope with index.
      Notation "xs ::' x" := (snoc xs x) : index_scope.
      Notation "[ ]" := nil : index_scope.
    End IndexNotations0.
    #[local] Open Scope index_scope.
Definition hd {r : Rank} : Index (S r) -> Index r.
exact (@fst _ _).
Defined.
Definition tl {r : Rank} : Index (S r) -> IndexType.
exact (@snd _ _).
Defined.
Fixpoint app {r1 r2 : Rank} {struct r2} : Index r1 -> Index r2 -> Index (r1 +' r2).
exact (match r2 with
         | 0%nat => fun sz _tt => sz
         | S r2 => fun sz1 sz2 => @app r1 r2 sz1 (hd sz2) ::' tl sz2
         end%index).
Defined.
    Fixpoint curriedT_dep {r : Rank} : (Index r -> Type) -> Type
      := match r with
         | O => fun f => f []
         | S r => fun f => curriedT_dep (fun init => forall i, f (init ::' i))
         end.
    Definition curriedT {r} (T : Type) : Type := @curriedT_dep r (fun _ => T).
Fixpoint uncurry_map_dep {r} : forall {A B}, (forall i, A i -> B i) -> @curriedT_dep r A -> (forall i : Index r, B i).
Admitted.
Definition uncurry_dep {r} {T} : @curriedT_dep r T -> (forall i : Index r, T i).
Admitted.
Definition uncurry {r T} : @curriedT r T -> (Index r -> T).
Admitted.
Definition uncurry_S {A r} : (Index 1 -> Index r -> A) -> (Index (1 +' r) -> A).
Admitted.

    Module Export UncurryNotation.
      Notation "'uncurry_fun' x1 .. xn => body"
        := (match _ return _ with
            | ty => uncurry_S (fun x1 => .. (uncurry_S (fun xn => match body return Index 0 -> ty with v => fun 'tt => v end)) .. )
            end)
             (only parsing, at level 200, x1 binder, xn binder, body at level 200).
    End UncurryNotation.

    End Make.

  Module ExtendedMake (IndexType : ExtendedIndexType).
    Include Make IndexType.

    End ExtendedMake.
End IndexGen.

Module Export Shape.
  Module ShapeType <: ExtendedIndexType.
Definition t : Type.
exact (int).
Defined.
  End ShapeType.

  Include IndexGen.ExtendedMake ShapeType.

  Module Export ShapeNotations.
    Declare Scope shape_scope.
    Delimit Scope shape_scope with shape.
    Bind Scope shape_scope with t.
    Notation "xs ::' x" := (snoc xs x) : shape_scope.
    Notation "[ ]" := nil : shape_scope.
    Notation "[ x ]" := (snoc nil x) : shape_scope.
    Notation "[ x ; y ; .. ; z ]" :=  (snoc .. (snoc (snoc nil x) y) .. z) : shape_scope.
    Notation "s1 ++' s2" := (app s1 s2) : shape_scope.
  End ShapeNotations.
End Shape.
Notation ShapeType := Shape.IndexType.
Notation Shape := Shape.Index.

Module Export RawIndex.
  Module RawIndexType <: ExtendedIndexType.
Definition t : Type.
exact (int).
Defined.
  End RawIndexType.

  Include IndexGen.ExtendedMake RawIndexType.

  End RawIndex.
Notation RawIndexType := RawIndex.IndexType.
Notation RawIndex := RawIndex.Index.

Module Export Index.
  Module IndexType <: ExtendedIndexType.
Definition t : Type.
Admitted.
  End IndexType.
End Index.
Monomorphic Definition tensor {r : Rank} (s : Shape r) (A : Type) : Type.
Admitted.

Declare Scope tensor_scope.
Delimit Scope tensor_scope with tensor.

Definition with_shape {r} (s : Shape r) {A} : @Shape.curriedT r A -> A.
Admitted.
Definition ones {r} (s : Shape r) {A} {one : has_one A} : tensor s A.
Admitted.
Definition raw_get {r} {s : Shape r} {A} (t : tensor s A) (idxs : RawIndex r) : A.
Admitted.
Definition uncurry {r} {s : Shape r} {A} : @RawIndex.curriedT r A -> tensor s A.
Admitted.
Definition map' {ra1 ra2 rb} {sa1 : Shape ra1} {sa2 : Shape ra2} {sb : Shape rb} {A B} (f : tensor sa2 A -> tensor sb B) (t : tensor (sa1 ++' sa2) A) : tensor (sa1 ++' sb) B.
Admitted.

Definition to_bool {r} {s : Shape r} {A} {zero : has_zero A} {eqb : has_eqb A} (xs : tensor s A) : tensor s bool.
Admitted.
Definition tril {rnk} {s : Shape rnk} {r c} {A} {zero : has_zero A}
  {diagonal : with_default "diagonal" int 0%int63} (input : tensor (s ++' [r; c]) A)
  : tensor (s ++' [r; c]) A.
Admitted.
Module Export Einsum.
Import Coq.Unicode.Utf8.

Import Ltac2.Ltac2.

Ltac2 mutable debug () := false.

Module Import Internals.
  Ltac2 debug_printf fmt := if debug () then Printf.printf fmt else Message.Format.kfprintf (fun x => ()) fmt.

  Ltac2 Notation "debug_printf" fmt(format) := debug_printf fmt.

  Ltac2 rec get_body (at_head : bool) (c : constr) :=
    match Constr.Unsafe.kind_nocast c with
    | Constr.Unsafe.Var v
      => let r := Std.VarRef v in
         eval cbv delta [$r] in c
    | Constr.Unsafe.Constant n _
      => let r := Std.ConstRef n in
         eval cbv delta [$r] in c
    | Constr.Unsafe.App f args
      => if at_head
         then let f := get_body at_head f in
              Constr.Unsafe.make (Constr.Unsafe.App f args)
         else c
    | _ => c
    end.

  Ltac2 shape_to_list (c : constr) : constr list
    := let rec aux c acc
         := lazy_match! c with
            | Shape.nil => acc
            | Shape.snoc ?cs ?c
              => aux cs (c :: acc)
            end in
       aux c [].

  Ltac2 ident_of_constr (c : constr) : ident option
    := match Constr.Unsafe.kind_nocast c with
       | Constr.Unsafe.Var v => Some v
       | _ => None
       end.

  Ltac2 toplevel_rels (c : constr) : int list
    := let rec aux (acc : int list) (c : constr)
         := match Constr.Unsafe.kind_nocast c with
            | Constr.Unsafe.Rel i => i :: acc
            | Constr.Unsafe.App f args
              => let acc := aux acc f in
                 Array.fold_right aux acc args
            | _ => acc
            end in
       List.sort_uniq Int.compare (aux [] c).

  Local Notation try_tc := (ltac:(try typeclasses eauto)) (only parsing).

  Ltac2 insert_all_einsums (sum_to : constr -> constr -> constr) (names : ident option list) (body : constr) : constr
    := let rawindexT := 'RawIndexType in
       let nbinders := List.length names in
       let body := Constr.Unsafe.liftn nbinders (Int.add 1 nbinders) body in
       let rec aux (names : ident option list) (rel_above : int) (body : constr) :   int * constr
         := match names with
            | [] => (1, body)
            | name :: names
              => let (cur_rel, body) := aux names (Int.add 1 rel_above) body in
                 (Int.add 1 cur_rel,
                   sum_to (mkRel (Int.add cur_rel rel_above)) (mkLambda (Constr.Binder.make name rawindexT) body))
            end in
       let (_, body) := aux names 0 body in
       body.

  Ltac2 constr_dropn (n : int) (k : int) (c : constr) : constr
    := let k := Int.sub k 1 in
       let invalid := mkVar (ident:(__CONSTR_DROPN_INVALID)) in
       debug_printf "dropping %i %i %t" n k c;
       let res := Constr.Unsafe.substnl (List.repeat invalid n) k c in
       debug_printf "dropped %i %i %t" n k res;
       res.

  Ltac2 Type exn ::= [ InternalEinsumNotEqual (constr, constr) ].
  Ltac2 Type exn ::= [ InternalEinsumNotEnoughArgs (int, constr, constr array) ].
  Ltac2 Type exn ::= [ InternalEinsumBadKind (Constr.Unsafe.kind) ].

  Ltac2 rec remove_dead_einsum_helper (hd_c : constr) (nargs : int) (names : 'a list) (body : constr) :   int *   int list * (  int *   constr)
    := match names with
       | [] => (1, toplevel_rels body, (0, body))
       | _ :: names
         => match Constr.Unsafe.kind_nocast body with
            | Constr.Unsafe.App f args
              => (if Int.ge nargs (Array.length args)
                  then Control.throw (InternalEinsumNotEnoughArgs nargs f args)
                  else ());
                 (let first_args := List.firstn nargs (Array.to_list args) in
                  let fargs := mkApp f first_args in
                  if Bool.neg (Constr.equal fargs hd_c)
                  then Control.throw (InternalEinsumNotEqual fargs hd_c)
                  else ());
                 let lam_body_pos := Int.sub (Array.length args) 1 in
                 let lam_body := Array.get args lam_body_pos in
                 match Constr.Unsafe.kind_nocast lam_body with
                 | Constr.Unsafe.Lambda b body
                   => let (cur_rel, used_rels, (accumulated_shift, body)) := remove_dead_einsum_helper hd_c nargs names body in
                      let (cur_rel_used, used_rels)
                        := match used_rels with
                           | r :: rs => if Int.equal cur_rel r
                                        then (true, rs)
                                        else (false, used_rels)
                           | [] => (false, used_rels)
                           end in
                      (Int.add cur_rel 1,
                        used_rels,
                        if cur_rel_used
                        then

                          let body := constr_dropn (Int.neg accumulated_shift) 1 body in
                          let lam_body := mkLambda b body in
                          Array.set args lam_body_pos lam_body;
                          (0, Constr.Unsafe.make (Constr.Unsafe.App f args))
                        else
                          (Int.sub accumulated_shift 1,
                            body))
                 | k => Control.throw (InternalEinsumBadKind k)
                 end
            | k => Control.throw (InternalEinsumBadKind k)
            end
       end.

  Ltac2 remove_dead_einsum (hd_c : constr) (nargs : int) (names : 'a list) (body : constr) : constr
    := debug_printf "remove dead from %t" body;
       let (_cur_rel, _used_rels, (accumulated_shift, body)) := remove_dead_einsum_helper hd_c nargs names body in

       constr_dropn (Int.neg accumulated_shift) 1 body.

  Ltac2 insert_einsums (ty : constr) (names : ident option list) (body : constr) : constr
    := let start := '(0%uint63) in
       let step := '(1%uint63) in
       let sum := '(@Reduction.sum $ty try_tc try_tc) in
       let sum_to stop body := mkApp sum [start; stop; step; body] in
       let body := insert_all_einsums sum_to names body in
       let n_sum_args := match Constr.Unsafe.kind_nocast sum with
                         | Constr.Unsafe.App _ args => Array.length args
                         | k => Control.throw (InternalEinsumBadKind k)
                         end in
       let body := remove_dead_einsum sum n_sum_args names body in
       body.

  Ltac2 Type exn ::= [ EinsumExtraNames (Constr.Unsafe.kind, ident option list) ].

  Ltac2 insert_all_einsums_below (ty : constr) (names : ident option list) (body : constr) : constr
    := let rec aux (cur_names : ident option list) (body : constr)
         := match cur_names with
            | [] => insert_einsums ty names body
            | n :: ns
              => match Constr.Unsafe.kind_nocast body with
                 | Constr.Unsafe.Lambda b body
                   => mkLambda b (aux ns body)
                 | k => Control.throw (EinsumExtraNames k cur_names)
                 end
            end in
       aux names body.

  Ltac2 make_einsum (shapes : constr list) (body : constr) : constr
    := let ty := Constr.type body in
       let c := Std.eval_pattern (List.map (fun s => (s, Std.AllOccurrences)) shapes) body in
       let names := List.map ident_of_constr shapes in
       match Constr.Unsafe.kind_nocast c with
       | Constr.Unsafe.App f shape_args
         => let f := insert_all_einsums_below ty names f in
            let f := Constr.Unsafe.make (Constr.Unsafe.App f shape_args) in

            let f := (eval cbv beta in f) in

            f
       | k
         => Control.throw (InternalEinsumBadKind k)
       end.

  Ltac subst_type_lets_in_goal _ :=
    repeat match goal with
      | [ H := [ _ ] : Type |- _ ] => match goal with |- context[H] => idtac end; subst H
      end.
End Internals.

Local Notation try_tc := (ltac2:(ltac1:(try typeclasses eauto))) (only parsing).

Local Notation indirect_einsum tensor_value ishape jshape
  := ltac2:(let get_body v := get_body false (Constr.pretype v) in
            let get_shape v := shape_to_list (get_body v) in
            let t := get_body tensor_value in
            let shapes := List.append (get_shape ishape) (get_shape jshape) in
            let t := make_einsum shapes t in
            exact $t)
             (only parsing).
#[local] Notation "'unify_rank_from_idxs' r @ i1 .. i_"
  := ((uncurry_fun i1 .. i_ => I) : RawIndex r -> True)
       (only parsing, i1 binder, i_ binder, at level 10).

#[export] Hint Extern 1 => progress subst_type_lets_in_goal () : typeclass_instances.
Declare Custom Entry einsum_args.

Notation "{{{ {{ i1 .. i_ , j1 .. j_ -> k1 .. k_ }} , t1 , t2 }}}"
  := (match t1%tensor, t2%tensor, _ as A, _ as B, _ as C, _ as r1, _ as r2, _ as r3, _ as s1, _ as s2, _ as s3 return @tensor _ s3 C with
      | t1', t2', A, B, C, r1, r2, r3, s1, s2, s3
        => match t1' : @tensor r1 s1 A, t2' : @tensor r2 s2 B return @tensor r3 s3 C with
           | t1', t2'
             => match
                 unify_rank_from_idxs r1 @ i1 .. i_,
                 unify_rank_from_idxs r2 @ j1 .. j_,
                 unify_rank_from_idxs r3 @ k1 .. k_
                   return @tensor r3 s3 C
                 with
               | _, _, _
                 => @with_shape
                      r1 s1 (tensor s3 C)
                      (λ i1 .. i_ ,
                        @with_shape
                          r2 s2 (tensor s3 C)
                          (λ j1 .. j_ ,
                            (match
                                (Shape.snoc .. (Shape.snoc Shape.nil i1) .. i_),
                                (Shape.snoc .. (Shape.snoc Shape.nil j1) .. j_)
                                return @tensor r3 s3 C
                              with
                              | __I_SHAPE, __J_SHAPE
                                => @Tensor.uncurry
                                     r3 s3 C
                                     (λ k1 .. k_ ,
                                       match @Arith.Classes.mul
                                               A B C try_tc
                                               (raw_get t1' (RawIndex.snoc .. (RawIndex.snoc RawIndex.nil i1) .. i_))
                                               (raw_get t2' (RawIndex.snoc .. (RawIndex.snoc RawIndex.nil j1) .. j_))
                                             return C
                                       with
                                       | __EINSUM_TENSOR_VALUE
                                         => indirect_einsum
                                              __EINSUM_TENSOR_VALUE __I_SHAPE __J_SHAPE
                                        end)
                               end)))
                end
           end
      end)
       (only parsing, in custom einsum_args at level 0, i1 binder, i_ binder, j1 binder, j_ binder, k1 binder, k_ binder, t1 constr at level 10, t2 constr at level 10).

Notation "'weaksauce_einsum' x"
  := (match x return _ with
      | y => ltac2:(let y := get_body false &y in
                    let z := (eval cbv beta iota delta [Tensor.with_shape Shape.uncurry Tensor.uncurry RawIndex.uncurry Shape.uncurry_dep RawIndex.uncurry_dep Shape.uncurry_map_dep RawIndex.uncurry_map_dep] in y) in
                    let z := (eval cbn beta iota delta [Nat.radd] in z) in
                    let z := (eval cbn beta iota zeta delta [Shape.snoc Shape.nil] in z) in

                    exact $z)
      end)
       (x custom einsum_args at level 10, at level 10, only parsing).

End Einsum.
Import NeuralNetInterp.Util.PArray.
  Section __.
    Context {r} {batch : Shape r}
      {pos n_heads d_model d_head} {n_ctx:N}
      {use_split_qkv_input : with_default "use_split_qkv_input" bool false}
      {A}
      {zeroA : has_zero A} {coerZ : has_coer Z A}
      {addA : has_add A} {subA : has_sub A} {mulA : has_mul A} {divA : has_div A}
      {maxA : has_max A}
      {sqrtA : has_sqrt A} {expA : has_exp A}
      (defaultA : pointed A := @coer _ _ coerZ point)
      {use_checkpoint : with_default "use_checkpoint" bool true}
      (W_Q W_K W_V W_O : tensor [n_heads; d_model; d_head] A)
      (b_Q b_K b_V : tensor [n_heads; d_head] A)
      (b_O : tensor [d_model] A)
      (IGNORE : A := coerZ (-1 * 10 ^ 5)%Z)
      (attn_scale : A := √(coer (Uint63.to_Z d_head)))
      (maybe_n_heads := fun b : bool => (if b return Shape (if b then _ else _) then [n_heads] else [])%shape)
      (query_input key_input value_input : tensor ((batch ::' pos) ++' (maybe_n_heads use_split_qkv_input ::' d_model)) A)
      (mask : tensor [n_ctx; n_ctx] bool := to_bool (tril (A:=bool) (ones [n_ctx; n_ctx]))).
Definition einsum_input
      (input : tensor ((batch ::' pos) ++' (maybe_n_heads use_split_qkv_input ::' d_model)) A)
      (W : tensor [n_heads; d_model; d_head] A)
      : tensor ((batch ::' pos) ++' [n_heads; d_head]) A.
exact (Tensor.map'
           (if use_split_qkv_input return tensor (maybe_n_heads use_split_qkv_input ::' d_model) A -> tensor [n_heads; d_head] A
            then fun input => weaksauce_einsum {{{ {{ head_index d_model,
                                          head_index d_model d_head
                                          -> head_index d_head }}
                                      , input
                                      , W }}}
            else fun input => weaksauce_einsum {{{ {{ d_model,
                                          head_index d_model d_head
                                          -> head_index d_head }}
                                      , input
                                      , W }}})
           input).
Intermediate Coq File (useful for debugging if minimization did not go as far as you wanted) (truncated to 8.0KiB; full 42KiB file on GitHub Actions Artifacts under tmp.v)
(* -*- mode: coq; coq-prog-args: ("-emacs" "-q" "-w" "+implicit-core-hint-db,+implicits-in-term,+non-reversible-notation,+deprecated-intros-until-0,+deprecated-focus,+unused-intro-pattern,+variable-collision,+unexpected-implicit-declaration,+omega-is-deprecated,+deprecated-instantiate-syntax,+non-recursive,+undeclared-scope,+deprecated-hint-rewrite-without-locality,+deprecated-hint-without-locality,+deprecated-instance-without-locality,+deprecated-typeclasses-transparency-without-locality,-ltac2-missing-notation-var,unsupported-attributes" "-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand" "-R" "/github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp/theories" "NeuralNetInterp" "-Q" "/github/workspace/cwd" "Top" "-Q" "/github/workspace/builds/coq/coq-failing/_install_ci/lib/coq/user-contrib/Ltac2" "Ltac2" "-top" "NeuralNetInterp.TransformerLens.HookedTransformer") -*- *)
(* File reduced by coq-bug-minimizer from original input, then from 473 lines to 51 lines, then from 64 lines to 441 lines, then from 445 lines to 322 lines, then from 335 lines to 1735 lines, then from 1740 lines to 476 lines, then from 489 lines to 648 lines, then from 653 lines to 476 lines, then from 489 lines to 788 lines, then from 793 lines to 467 lines, then from 480 lines to 1012 lines, then from 1017 lines to 469 lines, then from 482 lines to 847 lines, then from 852 lines to 477 lines, then from 490 lines to 718 lines, then from 723 lines to 501 lines, then from 514 lines to 548 lines, then from 553 lines to 512 lines, then from 525 lines to 559 lines, then from 564 lines to 513 lines, then from 526 lines to 560 lines, then from 565 lines to 519 lines, then from 532 lines to 637 lines, then from 642 lines to 522 lines, then from 535 lines to 624 lines, then from 629 lines to 527 lines, then from 540 lines to 609 lines, then from 614 lines to 539 lines, then from 552 lines to 630 lines, then from 635 lines to 552 lines, then from 565 lines to 617 lines, then from 622 lines to 568 lines, then from 581 lines to 1215 lines *)
(* coqc version 8.19+alpha compiled with OCaml 4.09.0
   coqtop version 8b9980c1a092:/builds/coq/coq/_build/default,(HEAD detached at 2564ef3) (2564ef398cf18455f1f1b63024e337c08cfbab26)
   Expected coqc runtime on this file: 0.000 sec *)
Require Coq.Init.Ltac.
Module Export AdmitTactic.
Module Import LocalFalse.
Inductive False : Prop := .
End LocalFalse.
Axiom proof_admitted : False.
Import Coq.Init.Ltac.
Tactic Notation "admit" := abstract case proof_admitted.
End AdmitTactic.
Require Ltac2.Constr.
Require Ltac2.Printf.
Require Ltac2.List.
Require Ltac2.Init.
Require Ltac2.Bool.
Require Ltac2.Ind.
Require Ltac2.Int.
Require Ltac2.Message.
Require Ltac2.Std.
Require Ltac2.Constr.
Require Ltac2.Control.
Require Ltac2.Pattern.
Require Ltac2.Array.

Module Ltac2_DOT_Notations_WRAPPED.
Module Notations.
(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *         Copyright INRIA, CNRS and contributors             *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
Import Ltac2.Init.

(** Constr matching *)

Ltac2 Notation "lazy_match!" t(tactic(6)) "with" m(constr_matching) "end" :=
  Pattern.lazy_match0 t m.

Ltac2 Notation "multi_match!" t(tactic(6)) "with" m(constr_matching) "end" :=
  Pattern.multi_match0 t m.

Ltac2 Notation "match!" t(tactic(6)) "with" m(constr_matching) "end" :=
  Pattern.one_match0 t m.

(** Goal matching *)

Ltac2 Notation "lazy_match!" "goal" "with" m(goal_matching) "end" :=
  Pattern.lazy_goal_match0 false m.

Ltac2 Notation "multi_match!" "goal" "with" m(goal_matching) "end" :=
  Pattern.multi_goal_match0 false m.

Ltac2 Notation "match!" "goal" "with" m(goal_matching) "end" :=
  Pattern.one_goal_match0 false m.

Ltac2 Notation "lazy_match!" "reverse" "goal" "with" m(goal_matching) "end" :=
  Pattern.lazy_goal_match0 true m.

Ltac2 Notation "multi_match!" "reverse" "goal" "with" m(goal_matching) "end" :=
  Pattern.multi_goal_match0 true m.

Ltac2 Notation "match!" "reverse" "goal" "with" m(goal_matching) "end" :=
  Pattern.one_goal_match0 true m.

(** Tacticals *)

Ltac2 orelse t f :=
match Control.case t with
| Err e => f e
| Val ans =>
  let (x, k) := ans in
  Control.plus (fun _ => x) k
end.

Ltac2 ifcatch t s f :=
match Control.case t with
| Err e => f e
| Val ans =>
  let (x, k) := ans in
  Control.plus (fun _ => s x) (fun e => s (k e))
end.

Ltac2 fail0 (_ : unit) := Control.enter (fun _ => Control.zero (Tactic_failure None)).

Ltac2 Notation fail := fail0 ().

Ltac2 try0 t := Control.enter (fun _ => orelse t (fun _ => ())).

Ltac2 Notation try := try0.

Ltac2 rec repeat0 (t : unit -> unit) :=
  Control.enter (fun () =>
    ifcatch (fun _ => Control.progress t)
      (fun _ => Control.check_interrupt (); repeat0 t) (fun _ => ())).

Ltac2 Notation repeat := repeat0.

Ltac2 dispatch0 t (head, tail) :=
  match tail with
  | None => Control.enter (fun _ => t (); Control.dispatch head)
  | Some tacs =>
    let (def, rem) := tacs in
    Control.enter (fun _ => t (); Control.extend head def rem)
  end.

Ltac2 Notation t(thunk(self)) ">" "[" l(dispatch) "]" : 4 := dispatch0 t l.

Ltac2 do0 n t :=
  let rec aux n t := match Int.equal n 0 with
  | true => ()
  | false => t (); aux (Int.sub n 1) t
  end in
  aux (n ()) t.

Ltac2 Notation do := do0.

Ltac2 Notation once := Control.once.

Ltac2 progress0 tac := Control.enter (fun _ => Control.progress tac).

Ltac2 Notation progress := progress0.

Ltac2 rec first0 tacs :=
match tacs with
| [] => Control.zero (Tactic_failure None)
| tac :: tacs => Control.enter (fun _ => orelse tac (fun _ => first0 tacs))
end.

Ltac2 Notation "first" "[" tacs(list0(thunk(tactic(6)), "|")) "]" := first0 tacs.

Ltac2 complete tac :=
  let ans := tac () in
  Control.enter (fun () => Control.zero (Tactic_failure None));
  ans.

Ltac2 rec solve0 tacs :=
match tacs with
| [] => Control.zero (Tactic_failure None)
| tac :: tacs =>
  Control.enter (fun _ => orelse (fun _ => complete tac) (fun _ => solve0 tacs))
end.

Ltac2 Notation "solve" "[" tacs(list0(thunk(tactic(6)), "|")) "]" := solve0 tacs.

Ltac2 time0 tac := Control.time None tac.

Ltac2 Notation time := time0.

Ltac2 abstract0 tac := Control.abstract None tac.

Ltac2 Notation abstract := abstract0.

(** Base tactics *)

(** Note that we redeclare notations that can be parsed as mere identifiers
    as abbreviations, so that it allows to parse them as function arguments
    without having to write them within parentheses. *)

(** Enter and check evar resolution *)
Ltac2 enter_h ev f arg :=
match ev with
| true => Control.enter (fun () => f ev (arg ()))
| false =>
  Control.enter (fun () =>
    Control.with_holes arg (fun x => f ev x))
end.

Ltac2 intros0 ev p :=
  Control.enter (fun () => Std.intros ev p).

Ltac2 Notation "intros" p(intropatterns) := intros0 false p.
Ltac2 Notation intros := intros.

Ltac2 Notation "eintros" p(intropatterns) := intros0 true p.
Ltac2 Notation eintros := eintros.

Ltac2 split0 ev bnd :=
  enter_h ev Std.split bnd.

Ltac2 Notation "split" bnd(thunk(with_bindings)) := split0 false bnd.
Ltac2 Notation split := split.

Ltac2 Notation "esplit" bnd(thunk(with_bindings)) := split0 true bnd.
Ltac2 Notation esplit := esplit.

Ltac2 exists0 ev bnds := match bnds with
| [] => split0 ev (fun () => Std.NoBindings)
| _ =>
  let rec aux bnds := match bnds with
  | [] => ()
  | bnd :: bnds => split0 ev bnd; aux bnds
  end in
  aux bnds
end.

Ltac2 Notation "exists" bnd(list0(thunk(bindings), ",")) := exists0 false bnd.
(* Ltac2 Notation exists := exists. *)

Ltac2 Notation "eexists" bnd(list0(thunk(bindings), ",")) := exists0 true bnd.
Ltac2 Notation eexists := eexists.

Ltac2 left0 ev bnd :
Build Log (contains the Coq error message) (truncated to last 8.0KiB; full 2.6MiB file on GitHub Actions Artifacts under build.log)
sr/sbin:/usr/bin:/sbin:/bin
++ export COQBIN=/github/workspace/builds/coq/coq-failing/_install_ci/bin/
++ COQBIN=/github/workspace/builds/coq/coq-failing/_install_ci/bin/
++ ls -l /github/workspace/builds/coq/coq-failing/_install_ci/bin/
total 361248
-rwxr-xr-x 1 root root     2136 Oct 14 08:02 coq-tex
-rwxr-xr-x 1 root root  2068464 Oct 13 16:28 coq-tex.orig
-rwxr-xr-x 1 root root  6279208 Oct 13 16:28 coq_makefile
-rwxr-xr-x 1 root root     2133 Oct 14 08:02 coqc
-rwxr-xr-x 1 root root     2138 Oct 14 08:02 coqc.byte
-rwxr-xr-x 1 root root 34322884 Oct 13 16:28 coqc.byte.orig
-rwxr-xr-x 1 root root 28850312 Oct 13 16:28 coqc.orig
-rwxr-xr-x 1 root root 12090456 Oct 13 16:28 coqchk
-rwxr-xr-x 1 root root  6713112 Oct 13 16:28 coqdep
-rwxr-xr-x 1 root root     2135 Oct 14 08:02 coqdoc
-rwxr-xr-x 1 root root  6413632 Oct 13 16:28 coqdoc.orig
-rwxr-xr-x 1 root root     2135 Oct 14 08:02 coqide
-rwxr-xr-x 1 root root 14556280 Oct 13 16:28 coqide.orig
-rwxr-xr-x 1 root root     2143 Oct 14 08:02 coqidetop.byte
-rwxr-xr-x 1 root root 34841914 Oct 13 16:28 coqidetop.byte.orig
-rwxr-xr-x 1 root root     2142 Oct 14 08:02 coqidetop.opt
-rwxr-xr-x 1 root root 29311160 Oct 13 16:28 coqidetop.opt.orig
-rwxr-xr-x 1 root root     2138 Oct 14 08:02 coqnative
-rwxr-xr-x 1 root root 12473552 Oct 13 16:28 coqnative.orig
-rwxr-xr-x 1 root root     2134 Oct 14 08:02 coqpp
-rwxr-xr-x 1 root root  2509024 Oct 13 16:28 coqpp.orig
-rwxr-xr-x 1 root root     2144 Oct 14 08:02 coqtimelog2html
-rwxr-xr-x 1 root root  2904440 Oct 13 16:28 coqtimelog2html.orig
-rwxr-xr-x 1 root root     2135 Oct 14 08:02 coqtop
-rwxr-xr-x 1 root root     2140 Oct 14 08:02 coqtop.byte
-rwxr-xr-x 1 root root 48353631 Oct 13 16:28 coqtop.byte.orig
-rwxr-xr-x 1 root root     2139 Oct 14 08:02 coqtop.opt
-rwxr-xr-x 1 root root 28850488 Oct 13 16:28 coqtop.opt.orig
-rwxr-xr-x 1 root root 28850488 Oct 13 16:28 coqtop.orig
-rwxr-xr-x 1 root root     2134 Oct 14 08:02 coqwc
-rwxr-xr-x 1 root root  1789672 Oct 13 16:28 coqwc.orig
-rwxr-xr-x 1 root root     2142 Oct 14 08:02 coqworker.opt
-rwxr-xr-x 1 root root 28856456 Oct 13 16:28 coqworker.opt.orig
-rwxr-xr-x 1 root root     2139 Oct 14 08:02 coqworkmgr
-rwxr-xr-x 1 root root  2378176 Oct 13 16:28 coqworkmgr.orig
-rwxr-xr-x 1 root root     2137 Oct 14 08:02 csdpcert
-rwxr-xr-x 1 root root 32349096 Oct 13 16:28 csdpcert.orig
-rwxr-xr-x 1 root root     2140 Oct 14 08:02 ocamllibdep
-rwxr-xr-x 1 root root  2353880 Oct 13 16:28 ocamllibdep.orig
-rwxr-xr-x 1 root root     2135 Oct 14 08:02 votour
-rwxr-xr-x 1 root root  2681240 Oct 13 16:28 votour.orig
++ CI_BUILD_DIR=/github/workspace/builds/coq/coq-failing/_build_ci
++ CI_INSTALL_DIR=/github/workspace/builds/coq/coq-failing/_install_ci
++ ls -l /github/workspace/builds/coq/coq-failing/_build_ci
total 4
drwxr-xr-x 6 root root 4096 Oct 13 16:59 neural_net_interp
++ declare -A overlays
++ set +x
+ git_download neural_net_interp
+ local project=neural_net_interp
+ local dest=/github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp
+ local giturl_var=neural_net_interp_CI_GITURL
+ local giturl=https://github.com/JasonGross/neural-net-coq-interp
+ local ref_var=neural_net_interp_CI_REF
+ local ref=tested
+ local ov_url=
+ local ov_ref=
+ '[' -d /github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp ']'
+ echo 'Warning: download and unpacking of neural_net_interp skipped because /github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp already exists.'
Warning: download and unpacking of neural_net_interp skipped because /github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp already exists.
+ '[' '' ']'
+ cd /github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp
+ make coq-ci-target
+ '[' -z x ']'
+ command make coq-ci-target
+ make coq-ci-target
make[1]: Entering directory '/github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp'
/github/workspace/builds/coq/coq-failing/_install_ci/bin/coq_makefile -f _CoqProject -o Makefile.coq
. etc/ensure_stack_limit.sh; \
 make --no-print-directory -f Makefile.coq coq-ci-target
Warning: Stack size (16384) may be too small.
Warning: To avoid stack overflows in OCaml native compilation, setting stack size to the recommended minimum of 65520 kbytes
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig --print-version 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.iYZ2duFSpD
MINIMIZER_DEBUG: files: 
COQC theories/TransformerLens/HookedTransformer.v
MINIMIZER_DEBUG_EXTRA: coqc: /github/workspace/builds/coq/coq-failing/_install_ci/bin///coqc
MINIMIZER_DEBUG_EXTRA: coqpath: 
MINIMIZER_DEBUG_EXTRA: pwd: PWD=/github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp
MINIMIZER_DEBUG_EXTRA: exec: /github/workspace/builds/coq/coq-failing/_install_ci/bin/coqc.orig -q -w +implicit-core-hint-db\,+implicits-in-term\,+non-reversible-notation\,+deprecated-intros-until-0\,+deprecated-focus\,+unused-intro-pattern\,+variable-collision\,+unexpected-implicit-declaration\,+omega-is-deprecated\,+deprecated-instantiate-syntax\,+non-recursive\,+undeclared-scope\,+deprecated-hint-rewrite-without-locality\,+deprecated-hint-without-locality\,+deprecated-instance-without-locality\,+deprecated-typeclasses-transparency-without-locality\,-ltac2-missing-notation-var\,unsupported-attributes -w -deprecated-native-compiler-option -native-compiler ondemand -R /github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp/theories NeuralNetInterp theories/TransformerLens/HookedTransformer.v 
MINIMIZER_DEBUG: info: /tmp/tmp-coqbot-minimizer.Q1vQohCeyo
MINIMIZER_DEBUG: files:  theories/TransformerLens/HookedTransformer.v
File "./theories/TransformerLens/HookedTransformer.v", line 139, characters 4-985:
Error:
Unable to satisfy the following constraints:
In environment:
r : Rank
batch : Shape r
pos, n_heads, d_model, d_head : ShapeType
n_ctx : N
use_split_qkv_input : with_default "use_split_qkv_input" false
A : Type
zeroA : has_zero A
coerZ : has_coer Z A
addA : has_add A
subA : has_sub A
mulA : has_mul A
divA : has_div A
maxA : has_max A
sqrtA : has_sqrt A
expA : has_exp A
defaultA := coer point : pointed A
use_checkpoint : with_default "use_checkpoint" true
W_Q, W_K, W_V, W_O : tensor [n_heads; d_model; d_head] A
b_Q, b_K, b_V : tensor [n_heads; d_head] A
b_O : tensor [d_model] A
IGNORE := coerZ (-1 * 10 ^ 5)%Z : A
attn_scale := √(coer φ (d_head)) : A
maybe_n_heads := fun b : bool =>
                 if b as b0 return (Shape (if b0 then 1%nat else 0%nat))
                 then [n_heads]%shape
                 else []%shape
 : forall b : bool, Shape (if b then 1%nat else 0%nat)
query_input, key_input,
value_input : tensor
                (batch ::' pos ++'
                 (maybe_n_heads use_split_qkv_input ::' d_model)) A
mask := to_bool (tril (ones [n_ctx; n_ctx])) : tensor [n_ctx; n_ctx] bool
input0 : tensor
           (batch ::' pos ++' (maybe_n_heads use_split_qkv_input ::' d_model))
           A
W : tensor [n_heads; d_model; d_head] A
input : tensor (maybe_n_heads true ::' d_model) A
t : tensor ?t A

?t : "Shape (1 +' (1 +' 0))"


Command exited with non-zero status 1
theories/TransformerLens/HookedTransformer.vo (real: 0.80, user: 0.56, sys: 0.24, mem: 475884 ko)
make[2]: *** [Makefile.coq:832: theories/TransformerLens/HookedTransformer.vo] Error 1
make[1]: *** [Makefile:42: invoke-coqmakefile] Error 2
make[1]: Leaving directory '/github/workspace/builds/coq/coq-failing/_build_ci/neural_net_interp'
Aggregating timing log...
    Time |  Peak Mem | File Name                           
-----------------------------------------------------------
0m00.56s | 475884 ko | Total Time / Peak Mem               
-----------------------------------------------------------
0m00.56s | 475884 ko | TransformerLens/HookedTransformer.vo
make: *** [Makefile.ci:172: ci-neural_net_interp] Error 2
/github/workspace/builds/coq /github/workspace
::endgroup::
Minimization Log (truncated to last 8.0KiB; full 1.3MiB file on GitHub Actions Artifacts under bug.log)
er.v", line 342, characters 2-45:
Warning: Notation "uncurry_fun _ .. _ => _" was already used.
[notation-overridden,parsing,default]
File "/tmp/tmp00p4xw_6/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 344, characters 2-15:
Warning: Notation "uncurry_fun _ .. _ => _" was already used.
[notation-overridden,parsing,default]
File "/tmp/tmp00p4xw_6/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 648, characters 47-53:
Error:
In environment
r : Rank
batch : Shape r
pos : ?T
n_heads : ShapeType
d_model : ShapeType
d_head : ShapeType
n_ctx : N
use_split_qkv_input : with_default "use_split_qkv_input" false
A : Type
zeroA : has_zero A
coerZ : has_coer Z A
addA : has_add A
subA : has_sub A
mulA : has_mul A
divA : has_div A
maxA : has_max A
sqrtA : has_sqrt A
expA : has_exp A
defaultA := coer point : pointed A
use_checkpoint : with_default "use_checkpoint" true
W_Q : tensor [n_heads; d_model; d_head] A
W_K : tensor [n_heads; d_model; d_head] A
W_V : tensor [n_heads; d_model; d_head] A
W_O : tensor [n_heads; d_model; d_head] A
b_Q : tensor [n_heads; d_head] A
b_K : tensor [n_heads; d_head] A
b_V : tensor [n_heads; d_head] A
b_O : tensor [d_model] A
IGNORE := coerZ (-1 * 10 ^ 5)%Z : A
The term "d_head" has type "ShapeType" while it is expected to have type
 "int".


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to admit lemmas with admit. Defined
�[92m
Admitting lemmas successful.�[0m
Failed to do everything at once; trying one at a time.
Admitting lemmas unsuccessful.
No successful changes.

I will now attempt to admit definitions with admit. Defined

Non-fatal error: Failed to admit definitions and preserve the error.  
The new error was:
File "/tmp/tmpcb9mmkjz/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 144, characters 0-11:
Warning: Trying to mask the absolute name "Ltac2.Constr.Unsafe"!
[masking-absolute-name,deprecated-since-8.8,deprecated,default]
File "/tmp/tmpcb9mmkjz/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 146, characters 0-11:
Warning: Trying to mask the absolute name "Ltac2.Constr"!
[masking-absolute-name,deprecated-since-8.8,deprecated,default]
File "/tmp/tmpcb9mmkjz/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 146, characters 0-11:
Warning: Trying to mask the absolute name "Ltac2.Constr.Unsafe"!
[masking-absolute-name,deprecated-since-8.8,deprecated,default]
File "/tmp/tmpcb9mmkjz/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 175, characters 0-8:
Error:  (in proof radd): Attempt to save a proof with given up goals. If this
is really what you want to do, use Admitted in place of Qed.


�[93mIntermediate code not saved.�[0m
Failed to do everything at once; trying one at a time.
Admitting definitions unsuccessful.
No successful changes.

I will now attempt to export modules
Module exportation unsuccessful.

I will now attempt to split imports and exports
Import/Export splitting unsuccessful.

I will now attempt to split := definitions
One-line definition splitting unsuccessful.

I will now attempt to remove all lines, one at a time
Line removal unsuccessful.

I will now attempt to remove goals ending in [Abort.]
�[92m
Aborted removal successful.�[0m

I will now attempt to remove unused Ltacs
�[92m
Ltac removal successful.�[0m

I will now attempt to remove unused definitions

Non-fatal error: Failed to remove definitions and preserve the error.  
The new error was:
File "/tmp/tmpqs1c2hf1/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 144, characters 0-11:
Warning: Trying to mask the absolute name "Ltac2.Constr.Unsafe"!
[masking-absolute-name,deprecated-since-8.8,deprecated,default]
File "/tmp/tmpqs1c2hf1/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 146, characters 0-11:
Warning: Trying to mask the absolute name "Ltac2.Constr"!
[masking-absolute-name,deprecated-since-8.8,deprecated,default]
File "/tmp/tmpqs1c2hf1/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 146, characters 0-11:
Warning: Trying to mask the absolute name "Ltac2.Constr.Unsafe"!
[masking-absolute-name,deprecated-since-8.8,deprecated,default]
File "/tmp/tmpqs1c2hf1/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 220, characters 2-8:
Warning: This command does not support this attribute: export.
[unsupported-attributes,parsing,default]
File "/tmp/tmpqs1c2hf1/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 221, characters 4-10:
Warning: This command does not support this attribute: export.
[unsupported-attributes,parsing,default]
File "/tmp/tmpqs1c2hf1/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 346, characters 2-45:
Warning: Notation "uncurry_fun _ .. _ => _" was already used.
[notation-overridden,parsing,default]
File "/tmp/tmpqs1c2hf1/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 348, characters 2-15:
Warning: Notation "uncurry_fun _ .. _ => _" was already used.
[notation-overridden,parsing,default]
File "/tmp/tmpqs1c2hf1/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 655, characters 44-51:
Error: Cannot infer the implicit parameter zero of to_bool whose type is
"has_zero bool" (no type class instance found) in
environment:
r : Rank
batch : Shape r
pos, n_heads, d_model, d_head : ShapeType
n_ctx : N
use_split_qkv_input : with_default "use_split_qkv_input" false
A : Type
zeroA : has_zero A
coerZ : has_coer Z A
addA : has_add A
subA : has_sub A
mulA : has_mul A
divA : has_div A
maxA : has_max A
sqrtA : has_sqrt A
expA : has_exp A
defaultA := coer point : pointed A
use_checkpoint : with_default "use_checkpoint" true
W_Q, W_K, W_V, W_O : tensor [n_heads; d_model; d_head] A
b_Q, b_K, b_V : tensor [n_heads; d_head] A
b_O : tensor [d_model] A
IGNORE := coerZ (-1 * 10 ^ 5)%Z : A
attn_scale := √(coer φ (d_head)) : A
maybe_n_heads := fun b : bool =>
                 if b as b0 return (Shape (if b0 then 1%nat else 0%nat))
                 then [n_heads]%shape
                 else []%shape
 : forall b : bool, Shape (if b then 1%nat else 0%nat)
query_input, key_input,
value_input : tensor
                (batch ::' pos ++'
                 (maybe_n_heads use_split_qkv_input ::' d_model)) A


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused non-instance, non-canonical structure definitions
�[92m
Non-instance definition removal successful.�[0m

I will now attempt to remove unused variables

Non-fatal error: Failed to remove variables and preserve the error.  
The new error was:
File "/tmp/tmpastsuql6/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 144, characters 0-11:
Warning: Trying to mask the absolute name "Ltac2.Constr.Unsafe"!
[masking-absolute-name,deprecated-since-8.8,deprecated,default]
File "/tmp/tmpastsuql6/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 146, characters 0-11:
Warning: Trying to mask the absolute name "Ltac2.Constr"!
[masking-absolute-name,deprecated-since-8.8,deprecated,default]
File "/tmp/tmpastsuql6/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 146, characters 0-11:
Warning: Trying to mask the absolute name "Ltac2.Constr.Unsafe"!
[masking-absolute-name,deprecated-since-8.8,deprecated,default]
File "/tmp/tmpastsuql6/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 228, characters 2-8:
Warning: This command does not support this attribute: export.
[unsupported-attributes,parsing,default]
File "/tmp/tmpastsuql6/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 229, characters 4-10:
Warning: This command does not support this attribute: export.
[unsupported-attributes,parsing,default]
File "/tmp/tmpastsuql6/NeuralNetInterp/TransformerLens/HookedTransformer.v", line 262, characters 26-37:
Error: The reference IndexType.t was not found in the current environment.


�[93mIntermediate code not saved.�[0m

I will now attempt to remove unused contexts
�[92m
Context removal successful.�[0m

I will now attempt to remove empty sections

No empty sections to remove.

Now, I will attempt to strip repeated newlines and trailing spaces from this file...

No strippable newlines or spaces.

If you have any comments on your experience of the minimizer, please share them in a reply (possibly tagging @JasonGross).
If you believe there's a bug in the bug minimizer, please report it on the bug minimizer issue tracker.

cc @JasonGross

@SkySkimmer SkySkimmer added the needs: overlay This is breaking external developments we track in CI. label Oct 14, 2023
@SkySkimmer
Copy link
Contributor Author

It seems the exact in

Notation "'weaksauce_einsum' x"
  := (match x return _ with
      | y => ltac2:(let y := get_body false &y in
                    let z := (eval cbv beta iota delta [Tensor.with_shape Shape.uncurry Tensor.uncurry RawIndex.uncurry Shape.uncurry_dep RawIndex.uncurry_dep Shape.uncurry_map_dep RawIndex.uncurry_map_dep] in y) in
                    let z := (eval cbn beta iota delta [Nat.radd] in z) in
                    let z := (eval cbn beta iota zeta delta [Shape.snoc Shape.nil] in z) in

                    exact $z)
      end)
       (x custom einsum_args at level 10, at level 10, only parsing).

produces an evar when unifying the type with the goal.

With the master implementation of exact Control.with_holes c (fun c => Control.refine (fun _ => c)) this is accepted as it sees the evar as not coming from c.

With this PR it is rejected (we do pretype constr_flags (OfType (goal())) c). Note that it's also rejected if we use ltac1's exact (ie ltac1:(z |- exact z) (Ltac1.of_constr z)).

IDK which behaviour should be considered correct.

@SkySkimmer
Copy link
Contributor Author

cc @JasonGross who wrote the code leading to the example

@JasonGross
Copy link
Member

produces an evar when unifying the type with the goal.

With the master implementation of exact Control.with_holes c (fun c => Control.refine (fun _ => c)) this is accepted as it sees the evar as not coming from c.

With this PR it is rejected (we do pretype constr_flags (OfType (goal())) c). Note that it's also rejected if we use ltac1's exact (ie ltac1:(z |- exact z) (Ltac1.of_constr z)).

IDK which behaviour should be considered correct.

I'm a bit confused, can you explain what's going on a bit more? My current understanding:

  1. When doing exact $z, the goal is an evar (?) (contains an evar?), and z itself contains an evar?
  2. The unification problem then instantiates some of the evars, but in the process creates new evars?
  3. Control.with_holes c (fun c => Control.refine (fun _ => c)) says "c is just $z, this does not create any new evars, so things are okay"
  4. pretype constr_flags (OfType (goal())) c rejects $z because ...?
  5. Ltac1 also rejects this exact because ....?

Ultimately, I'm happy to replace the exact $z with Control.refine (fun () => z) or refine $z or whatever, the code in neural-net-interp was not designed around a lack of holes or not and the intended semantics of this chunk of code probably more closely match doing refine (or eexact) rather than exact, but I'd like to understand what's going on here / have an even more minimal example.

@SkySkimmer
Copy link
Contributor Author

When doing exact $z, the goal is an evar (?) (contains an evar?), and z itself contains an evar?

The goal is an evar and z contains an evar.

The unification problem then instantiates some of the evars, but in the process creates new evars?

Not sure exactly but I guess so

Control.with_holes c (fun c => Control.refine (fun _ => c)) says "c is just $z, this does not create any new evars, so things are okay"

yes

pretype constr_flags (OfType (goal())) c rejects $z because ...?

there are new evars (?)

Ltac1 also rejects this exact because ....?

It does the same pretype call

SkySkimmer added a commit to SkySkimmer/neural-net-coq-interp that referenced this pull request Oct 20, 2023
@SkySkimmer SkySkimmer added the needs: changelog entry This should be documented in doc/changelog. label Oct 20, 2023
JasonGross pushed a commit to SkySkimmer/neural-net-coq-interp that referenced this pull request Oct 24, 2023
JasonGross pushed a commit to JasonGross/neural-net-coq-interp that referenced this pull request Oct 24, 2023
@SkySkimmer SkySkimmer added kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. part: ltac2 Issues and PRs related to the (in development) Ltac2 tactic langauge. request: full CI Use this label when you want your next push to trigger a full CI. and removed needs: overlay This is breaking external developments we track in CI. needs: changelog entry This should be documented in doc/changelog. labels Oct 24, 2023
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label Oct 30, 2023
@SkySkimmer SkySkimmer requested a review from a team October 30, 2023 12:18
@SkySkimmer SkySkimmer added this to the 8.19+rc1 milestone Oct 30, 2023
@coqbot-app
Copy link
Contributor

coqbot-app bot commented Oct 30, 2023

The job library:ci-fiat_crypto_legacy has failed in allow failure mode
ping @JasonGross

@github-actions github-actions bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Nov 2, 2023
@coqbot-app coqbot-app bot added needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. and removed needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. labels Nov 3, 2023
@ppedrot ppedrot self-assigned this Nov 6, 2023
(** Allows new unsolved evars. *)
End Flags.

Ltac2 Type expected_type := [ IsType | OfType (constr) | WithoutTypeConstraint ].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to expose this type as an ADT. For future-proofness it should come with opaque constructors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What change are you expecting?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An opaque type where the constructors are turned into externals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean what future are you proofing aganst.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know about the future, that's the point. As a rule of thumb, I think that Ltac2 should not transparently expose type implementations bound to the OCaml ones, except maybe low-level stuff like constr views.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@SkySkimmer SkySkimmer added the needs: progress Work in progress: awaiting action from the author. label Nov 13, 2023
Fix coq#12827

The implementation uses a generalization of Constr.pretype which takes
flags (an opaque type) and a typing constraint.

Changing `refine` is left to the future as the notation takes a tactic
thunk at constr type so would be backwards incompatible.
@SkySkimmer SkySkimmer added request: full CI Use this label when you want your next push to trigger a full CI. and removed needs: progress Work in progress: awaiting action from the author. labels Nov 13, 2023
@coqbot-app coqbot-app bot removed request: full CI Use this label when you want your next push to trigger a full CI. needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. labels Nov 13, 2023
@SkySkimmer
Copy link
Contributor Author

@coqbot run full ci
(pipeline is currently pending, remerge master to be compatible with just now merged overlays)

@ppedrot
Copy link
Member

ppedrot commented Nov 15, 2023

@coqbot run full ci

@ppedrot
Copy link
Member

ppedrot commented Nov 18, 2023

@coqbot merge now

@coqbot-app coqbot-app bot merged commit 057fc7f into coq:master Nov 18, 2023
10 of 12 checks passed
@SkySkimmer SkySkimmer deleted the ltac2-exact-preterm branch November 20, 2023 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. part: ltac2 Issues and PRs related to the (in development) Ltac2 tactic langauge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ltac2's exact is less powerful than Ltac1's exact
3 participants