zyra-network 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. zyra_network-0.0.1/PKG-INFO +56 -0
  2. zyra_network-0.0.1/README.md +38 -0
  3. zyra_network-0.0.1/ai/__init__.py +1 -0
  4. zyra_network-0.0.1/ai/agent/core_loop.py +159 -0
  5. zyra_network-0.0.1/ai/blockchain/ledger.py +168 -0
  6. zyra_network-0.0.1/ai/blockchain/pouw_validator.py +72 -0
  7. zyra_network-0.0.1/ai/blockchain/wallet.py +84 -0
  8. zyra_network-0.0.1/ai/brain/__init__.py +6 -0
  9. zyra_network-0.0.1/ai/brain/attention.py +81 -0
  10. zyra_network-0.0.1/ai/brain/base_model.py +33 -0
  11. zyra_network-0.0.1/ai/brain/baseline_mlp.py +87 -0
  12. zyra_network-0.0.1/ai/brain/feed_forward.py +30 -0
  13. zyra_network-0.0.1/ai/brain/model_factory.py +17 -0
  14. zyra_network-0.0.1/ai/brain/rms_norm.py +22 -0
  15. zyra_network-0.0.1/ai/brain/rope.py +73 -0
  16. zyra_network-0.0.1/ai/brain/transformer.py +97 -0
  17. zyra_network-0.0.1/ai/brain/transformer_block.py +38 -0
  18. zyra_network-0.0.1/ai/dataset/__init__.py +4 -0
  19. zyra_network-0.0.1/ai/dataset/builder.py +133 -0
  20. zyra_network-0.0.1/ai/dataset/corpus/__init__.py +5 -0
  21. zyra_network-0.0.1/ai/dataset/corpus/cleaner.py +85 -0
  22. zyra_network-0.0.1/ai/dataset/corpus/downloader.py +76 -0
  23. zyra_network-0.0.1/ai/dataset/corpus/extractor.py +91 -0
  24. zyra_network-0.0.1/ai/dataset/document.py +80 -0
  25. zyra_network-0.0.1/ai/dataset/instruction_reader.py +99 -0
  26. zyra_network-0.0.1/ai/dataset/metadata.py +67 -0
  27. zyra_network-0.0.1/ai/dataset/reader.py +114 -0
  28. zyra_network-0.0.1/ai/inference/generator.py +86 -0
  29. zyra_network-0.0.1/ai/inference/local_llm_client.py +268 -0
  30. zyra_network-0.0.1/ai/models/__init__.py +4 -0
  31. zyra_network-0.0.1/ai/models/metadata.py +76 -0
  32. zyra_network-0.0.1/ai/models/registry.py +64 -0
  33. zyra_network-0.0.1/ai/tokenizer/__init__.py +4 -0
  34. zyra_network-0.0.1/ai/tokenizer/bpe.py +86 -0
  35. zyra_network-0.0.1/ai/tokenizer/byte_codec.py +36 -0
  36. zyra_network-0.0.1/ai/tokenizer/serialization.py +69 -0
  37. zyra_network-0.0.1/ai/tokenizer/statistics.py +20 -0
  38. zyra_network-0.0.1/ai/tokenizer/tokenizer.py +107 -0
  39. zyra_network-0.0.1/ai/tokenizer/trainer.py +104 -0
  40. zyra_network-0.0.1/ai/tokenizer/vocabulary.py +53 -0
  41. zyra_network-0.0.1/ai/training/__init__.py +7 -0
  42. zyra_network-0.0.1/ai/training/checkpoint.py +179 -0
  43. zyra_network-0.0.1/ai/training/metrics.py +27 -0
  44. zyra_network-0.0.1/ai/training/reproducibility.py +24 -0
  45. zyra_network-0.0.1/ai/training/scheduler.py +34 -0
  46. zyra_network-0.0.1/ai/training/trainer.py +282 -0
  47. zyra_network-0.0.1/app/__init__.py +1 -0
  48. zyra_network-0.0.1/app/application.py +66 -0
  49. zyra_network-0.0.1/app/core/config.py +35 -0
  50. zyra_network-0.0.1/app/core/database.py +62 -0
  51. zyra_network-0.0.1/app/core/hardware.py +46 -0
  52. zyra_network-0.0.1/app/core/logging_service.py +43 -0
  53. zyra_network-0.0.1/app/core/memory.py +58 -0
  54. zyra_network-0.0.1/app/core/paths.py +27 -0
  55. zyra_network-0.0.1/app/core/rag.py +135 -0
  56. zyra_network-0.0.1/app/core/tools.py +322 -0
  57. zyra_network-0.0.1/app/core/voice.py +77 -0
  58. zyra_network-0.0.1/app/libs/PyPDF2/__init__.py +41 -0
  59. zyra_network-0.0.1/app/libs/PyPDF2/_cmap.py +413 -0
  60. zyra_network-0.0.1/app/libs/PyPDF2/_codecs/__init__.py +63 -0
  61. zyra_network-0.0.1/app/libs/PyPDF2/_codecs/adobe_glyphs.py +13437 -0
  62. zyra_network-0.0.1/app/libs/PyPDF2/_codecs/pdfdoc.py +264 -0
  63. zyra_network-0.0.1/app/libs/PyPDF2/_codecs/std.py +258 -0
  64. zyra_network-0.0.1/app/libs/PyPDF2/_codecs/symbol.py +260 -0
  65. zyra_network-0.0.1/app/libs/PyPDF2/_codecs/zapfding.py +261 -0
  66. zyra_network-0.0.1/app/libs/PyPDF2/_encryption.py +895 -0
  67. zyra_network-0.0.1/app/libs/PyPDF2/_merger.py +821 -0
  68. zyra_network-0.0.1/app/libs/PyPDF2/_page.py +2114 -0
  69. zyra_network-0.0.1/app/libs/PyPDF2/_protocols.py +62 -0
  70. zyra_network-0.0.1/app/libs/PyPDF2/_reader.py +1977 -0
  71. zyra_network-0.0.1/app/libs/PyPDF2/_security.py +252 -0
  72. zyra_network-0.0.1/app/libs/PyPDF2/_utils.py +471 -0
  73. zyra_network-0.0.1/app/libs/PyPDF2/_version.py +1 -0
  74. zyra_network-0.0.1/app/libs/PyPDF2/_writer.py +2822 -0
  75. zyra_network-0.0.1/app/libs/PyPDF2/constants.py +461 -0
  76. zyra_network-0.0.1/app/libs/PyPDF2/errors.py +54 -0
  77. zyra_network-0.0.1/app/libs/PyPDF2/filters.py +645 -0
  78. zyra_network-0.0.1/app/libs/PyPDF2/generic/__init__.py +144 -0
  79. zyra_network-0.0.1/app/libs/PyPDF2/generic/_annotations.py +275 -0
  80. zyra_network-0.0.1/app/libs/PyPDF2/generic/_base.py +648 -0
  81. zyra_network-0.0.1/app/libs/PyPDF2/generic/_data_structures.py +1382 -0
  82. zyra_network-0.0.1/app/libs/PyPDF2/generic/_fit.py +129 -0
  83. zyra_network-0.0.1/app/libs/PyPDF2/generic/_outline.py +35 -0
  84. zyra_network-0.0.1/app/libs/PyPDF2/generic/_rectangle.py +265 -0
  85. zyra_network-0.0.1/app/libs/PyPDF2/generic/_utils.py +172 -0
  86. zyra_network-0.0.1/app/libs/PyPDF2/pagerange.py +173 -0
  87. zyra_network-0.0.1/app/libs/PyPDF2/papersizes.py +48 -0
  88. zyra_network-0.0.1/app/libs/PyPDF2/py.typed +0 -0
  89. zyra_network-0.0.1/app/libs/PyPDF2/types.py +52 -0
  90. zyra_network-0.0.1/app/libs/PyPDF2/xmp.py +525 -0
  91. zyra_network-0.0.1/app/libs/click/__init__.py +144 -0
  92. zyra_network-0.0.1/app/libs/click/_compat.py +590 -0
  93. zyra_network-0.0.1/app/libs/click/_termui_impl.py +972 -0
  94. zyra_network-0.0.1/app/libs/click/_textwrap.py +188 -0
  95. zyra_network-0.0.1/app/libs/click/_utils.py +36 -0
  96. zyra_network-0.0.1/app/libs/click/_winconsole.py +297 -0
  97. zyra_network-0.0.1/app/libs/click/core.py +3799 -0
  98. zyra_network-0.0.1/app/libs/click/decorators.py +627 -0
  99. zyra_network-0.0.1/app/libs/click/exceptions.py +378 -0
  100. zyra_network-0.0.1/app/libs/click/formatting.py +320 -0
  101. zyra_network-0.0.1/app/libs/click/globals.py +67 -0
  102. zyra_network-0.0.1/app/libs/click/parser.py +533 -0
  103. zyra_network-0.0.1/app/libs/click/py.typed +0 -0
  104. zyra_network-0.0.1/app/libs/click/shell_completion.py +801 -0
  105. zyra_network-0.0.1/app/libs/click/termui.py +1014 -0
  106. zyra_network-0.0.1/app/libs/click/testing.py +798 -0
  107. zyra_network-0.0.1/app/libs/click/types.py +1422 -0
  108. zyra_network-0.0.1/app/libs/click/utils.py +688 -0
  109. zyra_network-0.0.1/app/libs/docx/__init__.py +65 -0
  110. zyra_network-0.0.1/app/libs/docx/api.py +37 -0
  111. zyra_network-0.0.1/app/libs/docx/blkcntnr.py +101 -0
  112. zyra_network-0.0.1/app/libs/docx/comments.py +163 -0
  113. zyra_network-0.0.1/app/libs/docx/dml/__init__.py +0 -0
  114. zyra_network-0.0.1/app/libs/docx/dml/color.py +112 -0
  115. zyra_network-0.0.1/app/libs/docx/document.py +265 -0
  116. zyra_network-0.0.1/app/libs/docx/drawing/__init__.py +59 -0
  117. zyra_network-0.0.1/app/libs/docx/enum/__init__.py +0 -0
  118. zyra_network-0.0.1/app/libs/docx/enum/base.py +150 -0
  119. zyra_network-0.0.1/app/libs/docx/enum/dml.py +103 -0
  120. zyra_network-0.0.1/app/libs/docx/enum/section.py +86 -0
  121. zyra_network-0.0.1/app/libs/docx/enum/shape.py +19 -0
  122. zyra_network-0.0.1/app/libs/docx/enum/style.py +452 -0
  123. zyra_network-0.0.1/app/libs/docx/enum/table.py +136 -0
  124. zyra_network-0.0.1/app/libs/docx/enum/text.py +367 -0
  125. zyra_network-0.0.1/app/libs/docx/exceptions.py +18 -0
  126. zyra_network-0.0.1/app/libs/docx/image/__init__.py +23 -0
  127. zyra_network-0.0.1/app/libs/docx/image/bmp.py +43 -0
  128. zyra_network-0.0.1/app/libs/docx/image/constants.py +172 -0
  129. zyra_network-0.0.1/app/libs/docx/image/exceptions.py +13 -0
  130. zyra_network-0.0.1/app/libs/docx/image/gif.py +38 -0
  131. zyra_network-0.0.1/app/libs/docx/image/helpers.py +86 -0
  132. zyra_network-0.0.1/app/libs/docx/image/image.py +234 -0
  133. zyra_network-0.0.1/app/libs/docx/image/jpeg.py +425 -0
  134. zyra_network-0.0.1/app/libs/docx/image/png.py +253 -0
  135. zyra_network-0.0.1/app/libs/docx/image/tiff.py +289 -0
  136. zyra_network-0.0.1/app/libs/docx/opc/__init__.py +0 -0
  137. zyra_network-0.0.1/app/libs/docx/opc/constants.py +306 -0
  138. zyra_network-0.0.1/app/libs/docx/opc/coreprops.py +142 -0
  139. zyra_network-0.0.1/app/libs/docx/opc/exceptions.py +12 -0
  140. zyra_network-0.0.1/app/libs/docx/opc/oxml.py +247 -0
  141. zyra_network-0.0.1/app/libs/docx/opc/package.py +219 -0
  142. zyra_network-0.0.1/app/libs/docx/opc/packuri.py +109 -0
  143. zyra_network-0.0.1/app/libs/docx/opc/part.py +247 -0
  144. zyra_network-0.0.1/app/libs/docx/opc/parts/__init__.py +0 -0
  145. zyra_network-0.0.1/app/libs/docx/opc/parts/coreprops.py +48 -0
  146. zyra_network-0.0.1/app/libs/docx/opc/phys_pkg.py +119 -0
  147. zyra_network-0.0.1/app/libs/docx/opc/pkgreader.py +254 -0
  148. zyra_network-0.0.1/app/libs/docx/opc/pkgwriter.py +115 -0
  149. zyra_network-0.0.1/app/libs/docx/opc/rel.py +153 -0
  150. zyra_network-0.0.1/app/libs/docx/opc/shared.py +31 -0
  151. zyra_network-0.0.1/app/libs/docx/opc/spec.py +24 -0
  152. zyra_network-0.0.1/app/libs/docx/oxml/__init__.py +251 -0
  153. zyra_network-0.0.1/app/libs/docx/oxml/comments.py +124 -0
  154. zyra_network-0.0.1/app/libs/docx/oxml/coreprops.py +298 -0
  155. zyra_network-0.0.1/app/libs/docx/oxml/document.py +88 -0
  156. zyra_network-0.0.1/app/libs/docx/oxml/drawing.py +11 -0
  157. zyra_network-0.0.1/app/libs/docx/oxml/exceptions.py +10 -0
  158. zyra_network-0.0.1/app/libs/docx/oxml/ns.py +109 -0
  159. zyra_network-0.0.1/app/libs/docx/oxml/numbering.py +109 -0
  160. zyra_network-0.0.1/app/libs/docx/oxml/parser.py +62 -0
  161. zyra_network-0.0.1/app/libs/docx/oxml/section.py +537 -0
  162. zyra_network-0.0.1/app/libs/docx/oxml/settings.py +138 -0
  163. zyra_network-0.0.1/app/libs/docx/oxml/shape.py +299 -0
  164. zyra_network-0.0.1/app/libs/docx/oxml/shared.py +52 -0
  165. zyra_network-0.0.1/app/libs/docx/oxml/simpletypes.py +434 -0
  166. zyra_network-0.0.1/app/libs/docx/oxml/styles.py +320 -0
  167. zyra_network-0.0.1/app/libs/docx/oxml/table.py +977 -0
  168. zyra_network-0.0.1/app/libs/docx/oxml/text/__init__.py +0 -0
  169. zyra_network-0.0.1/app/libs/docx/oxml/text/font.py +331 -0
  170. zyra_network-0.0.1/app/libs/docx/oxml/text/hyperlink.py +45 -0
  171. zyra_network-0.0.1/app/libs/docx/oxml/text/pagebreak.py +278 -0
  172. zyra_network-0.0.1/app/libs/docx/oxml/text/paragraph.py +106 -0
  173. zyra_network-0.0.1/app/libs/docx/oxml/text/parfmt.py +392 -0
  174. zyra_network-0.0.1/app/libs/docx/oxml/text/run.py +307 -0
  175. zyra_network-0.0.1/app/libs/docx/oxml/xmlchemy.py +696 -0
  176. zyra_network-0.0.1/app/libs/docx/package.py +110 -0
  177. zyra_network-0.0.1/app/libs/docx/parts/__init__.py +0 -0
  178. zyra_network-0.0.1/app/libs/docx/parts/comments.py +51 -0
  179. zyra_network-0.0.1/app/libs/docx/parts/document.py +169 -0
  180. zyra_network-0.0.1/app/libs/docx/parts/hdrftr.py +53 -0
  181. zyra_network-0.0.1/app/libs/docx/parts/image.py +80 -0
  182. zyra_network-0.0.1/app/libs/docx/parts/numbering.py +32 -0
  183. zyra_network-0.0.1/app/libs/docx/parts/settings.py +50 -0
  184. zyra_network-0.0.1/app/libs/docx/parts/story.py +95 -0
  185. zyra_network-0.0.1/app/libs/docx/parts/styles.py +42 -0
  186. zyra_network-0.0.1/app/libs/docx/py.typed +0 -0
  187. zyra_network-0.0.1/app/libs/docx/section.py +479 -0
  188. zyra_network-0.0.1/app/libs/docx/settings.py +35 -0
  189. zyra_network-0.0.1/app/libs/docx/shape.py +103 -0
  190. zyra_network-0.0.1/app/libs/docx/shared.py +382 -0
  191. zyra_network-0.0.1/app/libs/docx/styles/__init__.py +40 -0
  192. zyra_network-0.0.1/app/libs/docx/styles/latent.py +198 -0
  193. zyra_network-0.0.1/app/libs/docx/styles/style.py +254 -0
  194. zyra_network-0.0.1/app/libs/docx/styles/styles.py +136 -0
  195. zyra_network-0.0.1/app/libs/docx/table.py +537 -0
  196. zyra_network-0.0.1/app/libs/docx/text/__init__.py +0 -0
  197. zyra_network-0.0.1/app/libs/docx/text/font.py +428 -0
  198. zyra_network-0.0.1/app/libs/docx/text/hyperlink.py +121 -0
  199. zyra_network-0.0.1/app/libs/docx/text/pagebreak.py +104 -0
  200. zyra_network-0.0.1/app/libs/docx/text/paragraph.py +173 -0
  201. zyra_network-0.0.1/app/libs/docx/text/parfmt.py +286 -0
  202. zyra_network-0.0.1/app/libs/docx/text/run.py +257 -0
  203. zyra_network-0.0.1/app/libs/docx/text/tabstops.py +123 -0
  204. zyra_network-0.0.1/app/libs/docx/types.py +34 -0
  205. zyra_network-0.0.1/app/libs/duckduckgo_search/__init__.py +17 -0
  206. zyra_network-0.0.1/app/libs/duckduckgo_search/__main__.py +6 -0
  207. zyra_network-0.0.1/app/libs/duckduckgo_search/cli.py +371 -0
  208. zyra_network-0.0.1/app/libs/duckduckgo_search/duckduckgo_search.py +671 -0
  209. zyra_network-0.0.1/app/libs/duckduckgo_search/exceptions.py +14 -0
  210. zyra_network-0.0.1/app/libs/duckduckgo_search/py.typed +1 -0
  211. zyra_network-0.0.1/app/libs/duckduckgo_search/utils.py +66 -0
  212. zyra_network-0.0.1/app/libs/duckduckgo_search/version.py +1 -0
  213. zyra_network-0.0.1/app/libs/lxml/ElementInclude.py +244 -0
  214. zyra_network-0.0.1/app/libs/lxml/__init__.py +22 -0
  215. zyra_network-0.0.1/app/libs/lxml/_elementpath.py +343 -0
  216. zyra_network-0.0.1/app/libs/lxml/builder.py +243 -0
  217. zyra_network-0.0.1/app/libs/lxml/cssselect.py +101 -0
  218. zyra_network-0.0.1/app/libs/lxml/doctestcompare.py +488 -0
  219. zyra_network-0.0.1/app/libs/lxml/html/ElementSoup.py +10 -0
  220. zyra_network-0.0.1/app/libs/lxml/html/__init__.py +1927 -0
  221. zyra_network-0.0.1/app/libs/lxml/html/_diffcommand.py +86 -0
  222. zyra_network-0.0.1/app/libs/lxml/html/_difflib.py +2108 -0
  223. zyra_network-0.0.1/app/libs/lxml/html/_html5builder.py +100 -0
  224. zyra_network-0.0.1/app/libs/lxml/html/_setmixin.py +56 -0
  225. zyra_network-0.0.1/app/libs/lxml/html/builder.py +173 -0
  226. zyra_network-0.0.1/app/libs/lxml/html/clean.py +21 -0
  227. zyra_network-0.0.1/app/libs/lxml/html/defs.py +153 -0
  228. zyra_network-0.0.1/app/libs/lxml/html/diff.py +972 -0
  229. zyra_network-0.0.1/app/libs/lxml/html/formfill.py +299 -0
  230. zyra_network-0.0.1/app/libs/lxml/html/html5parser.py +260 -0
  231. zyra_network-0.0.1/app/libs/lxml/html/soupparser.py +314 -0
  232. zyra_network-0.0.1/app/libs/lxml/html/usedoctest.py +13 -0
  233. zyra_network-0.0.1/app/libs/lxml/includes/__init__.py +0 -0
  234. zyra_network-0.0.1/app/libs/lxml/includes/extlibs/__init__.py +0 -0
  235. zyra_network-0.0.1/app/libs/lxml/includes/libexslt/__init__.py +0 -0
  236. zyra_network-0.0.1/app/libs/lxml/includes/libxml/__init__.py +0 -0
  237. zyra_network-0.0.1/app/libs/lxml/includes/libxslt/__init__.py +0 -0
  238. zyra_network-0.0.1/app/libs/lxml/isoschematron/__init__.py +348 -0
  239. zyra_network-0.0.1/app/libs/lxml/pyclasslookup.py +3 -0
  240. zyra_network-0.0.1/app/libs/lxml/sax.py +285 -0
  241. zyra_network-0.0.1/app/libs/lxml/usedoctest.py +13 -0
  242. zyra_network-0.0.1/app/libs/primp/__init__.py +5 -0
  243. zyra_network-0.0.1/app/libs/primp/__init__.pyi +873 -0
  244. zyra_network-0.0.1/app/libs/primp/py.typed +0 -0
  245. zyra_network-0.0.1/app/libs/typing_extensions.py +4422 -0
  246. zyra_network-0.0.1/app/main.py +15 -0
  247. zyra_network-0.0.1/app/ui/agent_dashboard.py +135 -0
  248. zyra_network-0.0.1/app/ui/chat_bubble.py +291 -0
  249. zyra_network-0.0.1/app/ui/chat_page.py +1621 -0
  250. zyra_network-0.0.1/app/ui/dashboard_page.py +168 -0
  251. zyra_network-0.0.1/app/ui/logs_page.py +38 -0
  252. zyra_network-0.0.1/app/ui/main_window.py +268 -0
  253. zyra_network-0.0.1/app/ui/model_card.py +169 -0
  254. zyra_network-0.0.1/app/ui/models_page.py +371 -0
  255. zyra_network-0.0.1/app/ui/placeholders.py +14 -0
  256. zyra_network-0.0.1/app/ui/settings_page.py +22 -0
  257. zyra_network-0.0.1/app/ui/spotlight.py +71 -0
  258. zyra_network-0.0.1/app/ui/toast.py +79 -0
  259. zyra_network-0.0.1/app/ui/wallet_page.py +239 -0
  260. zyra_network-0.0.1/app/utils/web_search.py +39 -0
  261. zyra_network-0.0.1/app/workers/base_worker.py +39 -0
  262. zyra_network-0.0.1/app/workers/inference_worker.py +138 -0
  263. zyra_network-0.0.1/app/workers/ollama_installer.py +63 -0
  264. zyra_network-0.0.1/app/workers/tts_worker.py +65 -0
  265. zyra_network-0.0.1/app/workers/voice_worker.py +17 -0
  266. zyra_network-0.0.1/pyproject.toml +39 -0
  267. zyra_network-0.0.1/setup.cfg +4 -0
  268. zyra_network-0.0.1/tests/test_attention.py +59 -0
  269. zyra_network-0.0.1/tests/test_baseline_model.py +48 -0
  270. zyra_network-0.0.1/tests/test_bpe.py +47 -0
  271. zyra_network-0.0.1/tests/test_byte_codec.py +30 -0
  272. zyra_network-0.0.1/tests/test_causal_mask.py +42 -0
  273. zyra_network-0.0.1/tests/test_checkpoint.py +68 -0
  274. zyra_network-0.0.1/tests/test_config.py +18 -0
  275. zyra_network-0.0.1/tests/test_database.py +21 -0
  276. zyra_network-0.0.1/tests/test_dataset_builder.py +51 -0
  277. zyra_network-0.0.1/tests/test_dataset_reader.py +52 -0
  278. zyra_network-0.0.1/tests/test_dataset_validation.py +45 -0
  279. zyra_network-0.0.1/tests/test_device_fallback.py +27 -0
  280. zyra_network-0.0.1/tests/test_gradient_update.py +53 -0
  281. zyra_network-0.0.1/tests/test_hardware.py +17 -0
  282. zyra_network-0.0.1/tests/test_model_identity.py +56 -0
  283. zyra_network-0.0.1/tests/test_overfit_tiny_dataset.py +55 -0
  284. zyra_network-0.0.1/tests/test_paths.py +23 -0
  285. zyra_network-0.0.1/tests/test_pretraining_safety.py +34 -0
  286. zyra_network-0.0.1/tests/test_rms_norm.py +34 -0
  287. zyra_network-0.0.1/tests/test_rope.py +45 -0
  288. zyra_network-0.0.1/tests/test_tokenizer.py +55 -0
  289. zyra_network-0.0.1/tests/test_tokenizer_roundtrip.py +35 -0
  290. zyra_network-0.0.1/tests/test_tokenizer_serialization.py +31 -0
  291. zyra_network-0.0.1/tests/test_training_engine.py +32 -0
  292. zyra_network-0.0.1/tests/test_transformer_checkpoint.py +52 -0
  293. zyra_network-0.0.1/tests/test_transformer_model.py +48 -0
  294. zyra_network-0.0.1/tests/test_transformer_overfit.py +59 -0
  295. zyra_network-0.0.1/tests/test_weight_tying.py +23 -0
  296. zyra_network-0.0.1/zyra_cmd/__init__.py +1 -0
  297. zyra_network-0.0.1/zyra_cmd/zyra_cli.py +218 -0
  298. zyra_network-0.0.1/zyra_network.egg-info/PKG-INFO +56 -0
  299. zyra_network-0.0.1/zyra_network.egg-info/SOURCES.txt +301 -0
  300. zyra_network-0.0.1/zyra_network.egg-info/dependency_links.txt +1 -0
  301. zyra_network-0.0.1/zyra_network.egg-info/entry_points.txt +2 -0
  302. zyra_network-0.0.1/zyra_network.egg-info/requires.txt +12 -0
  303. zyra_network-0.0.1/zyra_network.egg-info/top_level.txt +3 -0
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.4
2
+ Name: zyra-network
3
+ Version: 0.0.1
4
+ Summary: A local agentic AI network that earns Proof of Useful Work (PoUW).
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: PySide6>=6.5.0
8
+ Requires-Dist: PyYAML>=6.0
9
+ Requires-Dist: torch>=2.0.0
10
+ Requires-Dist: psutil>=5.9.0
11
+ Requires-Dist: numpy>=1.24.0
12
+ Requires-Dist: httpx
13
+ Requires-Dist: openai
14
+ Requires-Dist: pyautogui
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest; extra == "dev"
17
+ Requires-Dist: pyinstaller; extra == "dev"
18
+
19
+ # MY-AI
20
+
21
+ A locally built, trained, and executed Artificial Intelligence desktop application for Windows.
22
+
23
+ ## Tujuan Project
24
+ Proyek ini dibuat untuk membangun neural network Transformer dan seluruh sistem pendukung AI dari awal tanpa bergantung pada layanan cloud, API eksternal, atau model pre-trained yang sudah ada (seperti OpenAI, Claude, Llama, dll).
25
+ Tujuan akhirnya adalah memiliki AI Assistant pribadi yang berjalan sepenuhnya lokal di komputer pengguna.
26
+
27
+ ## Requirements
28
+ - Windows 64-bit
29
+ - Python 3.10+
30
+ - Hardware minimal: CPU + RAM (Rekomendasi: NVIDIA GPU dengan CUDA support)
31
+
32
+ ## Setup Virtual Environment
33
+ ```powershell
34
+ python -m venv venv
35
+ .\venv\Scripts\activate
36
+ ```
37
+
38
+ ## Install Dependencies
39
+ Project ini menggunakan `pyproject.toml` untuk manajemen dependensi minimal.
40
+ ```powershell
41
+ pip install -e .[dev]
42
+ ```
43
+ Dependensi utama:
44
+ - PySide6 (Desktop GUI)
45
+ - PyYAML (Configuration)
46
+ - PyTorch (Hardware detection, Tensor/Autograd)
47
+
48
+ ## Menjalankan Aplikasi
49
+ ```powershell
50
+ python run.py
51
+ ```
52
+
53
+ ## Menjalankan Test
54
+ ```powershell
55
+ pytest tests/
56
+ ```
@@ -0,0 +1,38 @@
1
+ # MY-AI
2
+
3
+ A locally built, trained, and executed Artificial Intelligence desktop application for Windows.
4
+
5
+ ## Tujuan Project
6
+ Proyek ini dibuat untuk membangun neural network Transformer dan seluruh sistem pendukung AI dari awal tanpa bergantung pada layanan cloud, API eksternal, atau model pre-trained yang sudah ada (seperti OpenAI, Claude, Llama, dll).
7
+ Tujuan akhirnya adalah memiliki AI Assistant pribadi yang berjalan sepenuhnya lokal di komputer pengguna.
8
+
9
+ ## Requirements
10
+ - Windows 64-bit
11
+ - Python 3.10+
12
+ - Hardware minimal: CPU + RAM (Rekomendasi: NVIDIA GPU dengan CUDA support)
13
+
14
+ ## Setup Virtual Environment
15
+ ```powershell
16
+ python -m venv venv
17
+ .\venv\Scripts\activate
18
+ ```
19
+
20
+ ## Install Dependencies
21
+ Project ini menggunakan `pyproject.toml` untuk manajemen dependensi minimal.
22
+ ```powershell
23
+ pip install -e .[dev]
24
+ ```
25
+ Dependensi utama:
26
+ - PySide6 (Desktop GUI)
27
+ - PyYAML (Configuration)
28
+ - PyTorch (Hardware detection, Tensor/Autograd)
29
+
30
+ ## Menjalankan Aplikasi
31
+ ```powershell
32
+ python run.py
33
+ ```
34
+
35
+ ## Menjalankan Test
36
+ ```powershell
37
+ pytest tests/
38
+ ```
@@ -0,0 +1 @@
1
+ # AI Package
@@ -0,0 +1,159 @@
1
+ import logging
2
+ import json
3
+ import time
4
+ from typing import List, Dict, Any, Callable
5
+ from app.core.tools import execute_tool, TOOLS_SCHEMA
6
+
7
+ class AgentState:
8
+ IDLE = "IDLE"
9
+ THINKING = "THINKING"
10
+ ACTING = "ACTING"
11
+ OBSERVING = "OBSERVING"
12
+ COMPLETED = "COMPLETED"
13
+ ERROR = "ERROR"
14
+
15
+ class AutonomousAgent:
16
+ """
17
+ A robust ReAct-style Agent loop that can run long tasks and emit state changes.
18
+ This replaces the simple 5-iteration loop in the standard inference worker,
19
+ laying the groundwork for Proof-of-Useful-Work (PoUW).
20
+ """
21
+ def __init__(self, llm_client, max_iterations: int = 15):
22
+ self.llm_client = llm_client
23
+ self.max_iterations = max_iterations
24
+ self.state = AgentState.IDLE
25
+ self.logger = logging.getLogger("agent.core")
26
+
27
+ # Callbacks for UI updates
28
+ self.on_state_change: Callable[[str], None] = None
29
+ self.on_log: Callable[[str], None] = None
30
+
31
+ self.is_interrupted = False
32
+
33
+ def interrupt(self):
34
+ self.is_interrupted = True
35
+ self.llm_client.interrupt()
36
+
37
+ def _set_state(self, new_state: str):
38
+ self.state = new_state
39
+ if self.on_state_change:
40
+ self.on_state_change(self.state)
41
+
42
+ def _log(self, msg: str):
43
+ self.logger.info(msg)
44
+ if self.on_log:
45
+ self.on_log(msg)
46
+
47
+ def run_task(
48
+ self,
49
+ task_prompt: str,
50
+ system_context: str = "",
51
+ security_callback: Callable = None
52
+ ) -> str:
53
+ """
54
+ Executes a task autonomously until completion or max iterations.
55
+ """
56
+ self.is_interrupted = False
57
+ self._set_state(AgentState.THINKING)
58
+ self._log(f"Task started: {task_prompt}")
59
+
60
+ messages = [
61
+ {"role": "system", "content": system_context},
62
+ {"role": "user", "content": task_prompt}
63
+ ]
64
+
65
+ iteration = 0
66
+ final_answer = ""
67
+
68
+ while iteration < self.max_iterations:
69
+ if self.is_interrupted:
70
+ self._log("Task interrupted by user.")
71
+ self._set_state(AgentState.ERROR)
72
+ return "Interrupted."
73
+
74
+ iteration += 1
75
+ self._log(f"--- Iteration {iteration}/{self.max_iterations} ---")
76
+ self._set_state(AgentState.THINKING)
77
+
78
+ try:
79
+ # Call LLM via standard API
80
+ response = self.llm_client.client.chat.completions.create(
81
+ model=self.llm_client.model_name,
82
+ messages=messages,
83
+ tools=TOOLS_SCHEMA,
84
+ temperature=0.7,
85
+ )
86
+
87
+ message = response.choices[0].message
88
+
89
+ # Log thought process if any
90
+ if message.content:
91
+ self._log(f"Agent Thought:\n{message.content}")
92
+ final_answer = message.content # Keep updating final answer
93
+
94
+ # Check for tool calls
95
+ if message.tool_calls:
96
+ self._set_state(AgentState.ACTING)
97
+
98
+ # Append assistant's tool calls to context
99
+ assistant_msg = {
100
+ "role": "assistant",
101
+ "content": message.content,
102
+ "tool_calls": [
103
+ {
104
+ "id": tc.id,
105
+ "type": "function",
106
+ "function": {
107
+ "name": tc.function.name,
108
+ "arguments": tc.function.arguments
109
+ }
110
+ } for tc in message.tool_calls
111
+ ]
112
+ }
113
+ messages.append(assistant_msg)
114
+
115
+ for tc in message.tool_calls:
116
+ func_name = tc.function.name
117
+ try:
118
+ args = json.loads(tc.function.arguments)
119
+ except json.JSONDecodeError:
120
+ args = {}
121
+
122
+ self._log(f"Executing Tool: {func_name}")
123
+
124
+ # Execute Tool
125
+ result_str = execute_tool(func_name, args, security_callback)
126
+
127
+ self._set_state(AgentState.OBSERVING)
128
+
129
+ # Truncate output for log UI to avoid freezing
130
+ log_out = result_str
131
+ if len(log_out) > 500:
132
+ log_out = log_out[:500] + "... (truncated)"
133
+ self._log(f"Tool Output:\n{log_out}")
134
+
135
+ # Append observation to context
136
+ messages.append({
137
+ "role": "tool",
138
+ "tool_call_id": tc.id,
139
+ "content": result_str
140
+ })
141
+
142
+ # Loop back to THINKING with the new context
143
+ continue
144
+ else:
145
+ # No tool calls means the agent is done
146
+ self._log("Task completed successfully.")
147
+ self._set_state(AgentState.COMPLETED)
148
+ # Append final answer to messages to save it in memory if needed
149
+ messages.append({"role": "assistant", "content": final_answer})
150
+ return final_answer
151
+
152
+ except Exception as e:
153
+ self._log(f"Error during iteration: {str(e)}")
154
+ self._set_state(AgentState.ERROR)
155
+ return f"Error: {str(e)}"
156
+
157
+ self._log("Max iterations reached without completion.")
158
+ self._set_state(AgentState.ERROR)
159
+ return final_answer + "\n[Warning: Task terminated because max iterations were reached.]"
@@ -0,0 +1,168 @@
1
+ import sqlite3
2
+ import os
3
+ import json
4
+ import hashlib
5
+ import time
6
+
7
+ class ZyraLedger:
8
+ """
9
+ A local SQLite-based blockchain ledger for the ZYRA token ecosystem.
10
+ Records Proof of Useful Work (PoUW) minting events and P2P transactions.
11
+ """
12
+ def __init__(self, data_dir: str):
13
+ self.db_path = os.path.join(data_dir, "ledger.db")
14
+ os.makedirs(data_dir, exist_ok=True)
15
+ self._init_db()
16
+
17
+ def _init_db(self):
18
+ conn = sqlite3.connect(self.db_path)
19
+ c = conn.cursor()
20
+
21
+ # Blocks Table
22
+ c.execute('''
23
+ CREATE TABLE IF NOT EXISTS blocks (
24
+ height INTEGER PRIMARY KEY AUTOINCREMENT,
25
+ timestamp REAL,
26
+ prev_hash TEXT,
27
+ merkle_root TEXT,
28
+ hash TEXT UNIQUE
29
+ )
30
+ ''')
31
+
32
+ # Transactions Table
33
+ c.execute('''
34
+ CREATE TABLE IF NOT EXISTS transactions (
35
+ txid TEXT PRIMARY KEY,
36
+ block_height INTEGER,
37
+ sender TEXT,
38
+ receiver TEXT,
39
+ amount REAL,
40
+ type TEXT, -- 'MINT' (PoUW) or 'TRANSFER'
41
+ signature TEXT,
42
+ timestamp REAL,
43
+ FOREIGN KEY(block_height) REFERENCES blocks(height)
44
+ )
45
+ ''')
46
+
47
+ # Balances Table (Account based for simplicity in local env)
48
+ c.execute('''
49
+ CREATE TABLE IF NOT EXISTS balances (
50
+ address TEXT PRIMARY KEY,
51
+ balance REAL DEFAULT 0.0
52
+ )
53
+ ''')
54
+
55
+ conn.commit()
56
+
57
+ # Create Genesis Block if empty
58
+ c.execute("SELECT COUNT(*) FROM blocks")
59
+ if c.fetchone()[0] == 0:
60
+ self._create_genesis_block(c)
61
+ conn.commit()
62
+
63
+ conn.close()
64
+
65
+ def _create_genesis_block(self, cursor):
66
+ genesis_hash = hashlib.sha256(b"ZYRA_GENESIS_BLOCK").hexdigest()
67
+ cursor.execute('''
68
+ INSERT INTO blocks (timestamp, prev_hash, merkle_root, hash)
69
+ VALUES (?, ?, ?, ?)
70
+ ''', (time.time(), "0"*64, "0"*64, genesis_hash))
71
+
72
+ def get_balance(self, address: str) -> float:
73
+ conn = sqlite3.connect(self.db_path)
74
+ c = conn.cursor()
75
+ c.execute("SELECT balance FROM balances WHERE address = ?", (address,))
76
+ row = c.fetchone()
77
+ conn.close()
78
+ return row[0] if row else 0.0
79
+
80
+ def add_pouw_reward(self, receiver_address: str, amount: float, task_proof: dict) -> str:
81
+ """
82
+ Mints new ZYRA tokens to the receiver for completing a valid AI task.
83
+ """
84
+ conn = sqlite3.connect(self.db_path)
85
+ c = conn.cursor()
86
+
87
+ timestamp = time.time()
88
+
89
+ # Simple Block Generation (1 tx per block for now)
90
+ c.execute("SELECT hash, height FROM blocks ORDER BY height DESC LIMIT 1")
91
+ prev_block = c.fetchone()
92
+ prev_hash = prev_block[0]
93
+ new_height = prev_block[1] + 1
94
+
95
+ tx_data = f"MINT:{receiver_address}:{amount}:{timestamp}:{json.dumps(task_proof)}"
96
+ txid = hashlib.sha256(tx_data.encode()).hexdigest()
97
+
98
+ # Create Block
99
+ block_hash = hashlib.sha256(f"{new_height}{timestamp}{prev_hash}{txid}".encode()).hexdigest()
100
+ c.execute('''
101
+ INSERT INTO blocks (height, timestamp, prev_hash, merkle_root, hash)
102
+ VALUES (?, ?, ?, ?, ?)
103
+ ''', (new_height, timestamp, prev_hash, txid, block_hash))
104
+
105
+ # Insert Transaction
106
+ c.execute('''
107
+ INSERT INTO transactions (txid, block_height, sender, receiver, amount, type, signature, timestamp)
108
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
109
+ ''', (txid, new_height, "SYSTEM", receiver_address, amount, "MINT", "POUW_VALIDATED", timestamp))
110
+
111
+ # Update Balance
112
+ c.execute("INSERT OR IGNORE INTO balances (address, balance) VALUES (?, 0.0)", (receiver_address,))
113
+ c.execute("UPDATE balances SET balance = balance + ? WHERE address = ?", (amount, receiver_address))
114
+
115
+ conn.commit()
116
+ conn.close()
117
+ return txid
118
+
119
+ def get_recent_transactions(self, limit=10):
120
+ conn = sqlite3.connect(self.db_path)
121
+ c = conn.cursor()
122
+ c.execute('''
123
+ SELECT txid, type, amount, receiver, timestamp
124
+ FROM transactions
125
+ ORDER BY timestamp DESC LIMIT ?
126
+ ''', (limit,))
127
+ rows = c.fetchall()
128
+ conn.close()
129
+
130
+ result = []
131
+ for r in rows:
132
+ result.append({
133
+ "txid": r[0],
134
+ "type": r[1],
135
+ "amount": r[2],
136
+ "receiver": r[3],
137
+ "timestamp": r[4]
138
+ })
139
+ return result
140
+
141
+ def add_withdraw_transaction(self, sender_address: str, amount: float, web3_txid: str):
142
+ conn = sqlite3.connect(self.db_path)
143
+ c = conn.cursor()
144
+
145
+ timestamp = time.time()
146
+ c.execute("SELECT hash, height FROM blocks ORDER BY height DESC LIMIT 1")
147
+ prev_block = c.fetchone()
148
+ prev_hash = prev_block[0]
149
+ new_height = prev_block[1] + 1
150
+
151
+ # We store the web3_txid as the local txid for cross-reference
152
+ txid = web3_txid if web3_txid else hashlib.sha256(f"WITHDRAW:{sender_address}:{amount}:{timestamp}".encode()).hexdigest()
153
+
154
+ block_hash = hashlib.sha256(f"{new_height}{timestamp}{prev_hash}{txid}".encode()).hexdigest()
155
+ c.execute('''
156
+ INSERT INTO blocks (height, timestamp, prev_hash, merkle_root, hash)
157
+ VALUES (?, ?, ?, ?, ?)
158
+ ''', (new_height, timestamp, prev_hash, txid, block_hash))
159
+
160
+ c.execute('''
161
+ INSERT INTO transactions (txid, block_height, sender, receiver, amount, type, signature, timestamp)
162
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
163
+ ''', (txid, new_height, sender_address, "WEB3_BRIDGE", amount, "WITHDRAW", "LOCAL_AUTH", timestamp))
164
+
165
+ c.execute("UPDATE balances SET balance = balance - ? WHERE address = ?", (amount, sender_address))
166
+
167
+ conn.commit()
168
+ conn.close()
@@ -0,0 +1,72 @@
1
+ import hashlib
2
+ import json
3
+ import time
4
+ import math
5
+
6
+ class PoUWValidator:
7
+ """
8
+ Proof of Useful Work (PoUW) Validator.
9
+ Instead of hashing empty blocks, we validate the computational work done during AI inference/agent tasks.
10
+ """
11
+
12
+ BASE_REWARD_PER_TOKEN = 0.0001
13
+ DIFFICULTY_MULTIPLIER = 1.0
14
+
15
+ @classmethod
16
+ def calculate_reward(cls, tokens_generated: int, latency_ms: float, vram_mb: float, is_tool_call: bool) -> float:
17
+ """
18
+ Calculates the amount of ZYRA to reward based on the useful work performed.
19
+ Heavier tasks (more tokens, using tools, utilizing more VRAM) yield higher rewards.
20
+ """
21
+ if tokens_generated <= 0:
22
+ return 0.0
23
+
24
+ # Base reward scales linearly with tokens generated
25
+ base = tokens_generated * cls.BASE_REWARD_PER_TOKEN
26
+
27
+ # Multiplier for tool usage (Agentic work is more valuable than passive chat)
28
+ tool_multiplier = 1.5 if is_tool_call else 1.0
29
+
30
+ # Hardware multiplier (Simulates higher rewards for offering more compute power)
31
+ # Using log10 so it doesn't scale infinitely
32
+ hw_multiplier = math.log10(max(10, vram_mb)) / math.log10(8192) if vram_mb > 0 else 1.0
33
+
34
+ # Calculate final reward
35
+ reward = base * tool_multiplier * hw_multiplier * cls.DIFFICULTY_MULTIPLIER
36
+
37
+ # Cap reward per single inference task to prevent abuse
38
+ return round(min(reward, 50.0), 6)
39
+
40
+ @classmethod
41
+ def generate_proof(cls, task_type: str, prompt: str, tokens: int, metrics: dict, wallet_address: str) -> dict:
42
+ """
43
+ Generates a cryptographic proof of the work done.
44
+ In a real P2P network, nodes would verify this proof against a model checkpoint.
45
+ For local simulation, we sign the metrics with the system timestamp.
46
+ """
47
+ timestamp = time.time()
48
+
49
+ # Check if tools were used (indicated by task_type or metrics)
50
+ is_tool = task_type == 'AGENT_EXECUTION'
51
+
52
+ vram_mb = metrics.get('vram_mb', 0.0)
53
+ latency_ms = metrics.get('latency_ms', 0.0)
54
+
55
+ reward = cls.calculate_reward(tokens, latency_ms, vram_mb, is_tool)
56
+
57
+ proof_payload = {
58
+ "task_type": task_type,
59
+ "wallet": wallet_address,
60
+ "tokens": tokens,
61
+ "metrics": metrics,
62
+ "timestamp": timestamp,
63
+ "reward": reward
64
+ }
65
+
66
+ # Create a verifiable hash of the payload
67
+ payload_str = json.dumps(proof_payload, sort_keys=True)
68
+ proof_hash = hashlib.sha256(payload_str.encode()).hexdigest()
69
+
70
+ proof_payload["proof_hash"] = proof_hash
71
+
72
+ return proof_payload
@@ -0,0 +1,84 @@
1
+ import os
2
+ import json
3
+ import hashlib
4
+ import binascii
5
+ try:
6
+ import ecdsa
7
+ HAS_ECDSA = True
8
+ except ImportError:
9
+ HAS_ECDSA = False
10
+
11
+ class ZyraWallet:
12
+ """
13
+ Handles cryptographic keys and signing for the local ZYRA token ecosystem.
14
+ Uses ECDSA SECP256k1 if available, otherwise falls back to a simulated hash (for testing).
15
+ """
16
+ def __init__(self, data_dir: str):
17
+ self.wallet_file = os.path.join(data_dir, "wallet.json")
18
+ self.private_key = None
19
+ self.public_key = None
20
+ self.address = None
21
+ self.load_or_create_wallet()
22
+
23
+ def _generate_simulated_keys(self):
24
+ """Fallback if ecdsa is not installed. Not secure!"""
25
+ import uuid
26
+ self.private_key = hashlib.sha256(str(uuid.uuid4()).encode()).hexdigest()
27
+ self.public_key = hashlib.sha256(self.private_key.encode()).hexdigest()
28
+ self.address = "Z" + hashlib.ripemd160(self.public_key.encode()).hexdigest() if hasattr(hashlib, 'ripemd160') else "Z" + self.public_key[:40]
29
+
30
+ def _generate_ecdsa_keys(self):
31
+ """Secure key generation using secp256k1 (Bitcoin standard)."""
32
+ sk = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1)
33
+ vk = sk.get_verifying_key()
34
+
35
+ self.private_key = sk.to_string().hex()
36
+ self.public_key = vk.to_string().hex()
37
+
38
+ # Hash pubkey to get address (SHA256 then RIPEMD160 usually, here we use double SHA256 for simplicity if RIPEMD missing)
39
+ pub_hash = hashlib.sha256(self.public_key.encode()).hexdigest()
40
+ self.address = "Z" + pub_hash[:40] # Z-prefix for ZYRA
41
+
42
+ def load_or_create_wallet(self):
43
+ if os.path.exists(self.wallet_file):
44
+ with open(self.wallet_file, 'r') as f:
45
+ data = json.load(f)
46
+ self.private_key = data.get('private_key')
47
+ self.public_key = data.get('public_key')
48
+ self.address = data.get('address')
49
+ else:
50
+ if HAS_ECDSA:
51
+ self._generate_ecdsa_keys()
52
+ else:
53
+ self._generate_simulated_keys()
54
+
55
+ os.makedirs(os.path.dirname(self.wallet_file), exist_ok=True)
56
+ with open(self.wallet_file, 'w') as f:
57
+ json.dump({
58
+ "private_key": self.private_key,
59
+ "public_key": self.public_key,
60
+ "address": self.address
61
+ }, f, indent=4)
62
+
63
+ def sign_transaction(self, tx_data: str) -> str:
64
+ """Signs a transaction payload string with the private key."""
65
+ if HAS_ECDSA and len(self.private_key) == 64: # 32 bytes hex
66
+ try:
67
+ sk = ecdsa.SigningKey.from_string(bytes.fromhex(self.private_key), curve=ecdsa.SECP256k1)
68
+ signature = sk.sign(tx_data.encode())
69
+ return signature.hex()
70
+ except Exception:
71
+ pass
72
+
73
+ # Fallback simulated signature
74
+ return hashlib.sha256((self.private_key + tx_data).encode()).hexdigest()
75
+
76
+ @staticmethod
77
+ def verify_signature(public_key: str, signature: str, tx_data: str) -> bool:
78
+ if HAS_ECDSA and len(public_key) == 128:
79
+ try:
80
+ vk = ecdsa.VerifyingKey.from_string(bytes.fromhex(public_key), curve=ecdsa.SECP256k1)
81
+ return vk.verify(bytes.fromhex(signature), tx_data.encode())
82
+ except Exception:
83
+ return False
84
+ return True # Fallback mode accepts all
@@ -0,0 +1,6 @@
1
+ from .base_model import BaseLanguageModel
2
+ from .baseline_mlp import FixedContextMLP
3
+ from .transformer import MyAIDecoderTransformer
4
+ from .model_factory import create_model
5
+
6
+ __all__ = ["BaseLanguageModel", "FixedContextMLP", "MyAIDecoderTransformer", "create_model"]
@@ -0,0 +1,81 @@
1
+ import torch
2
+ import torch.nn as nn
3
+ import torch.nn.functional as F
4
+ from typing import Dict, Any, Optional
5
+
6
+ from .rope import RotaryPositionalEmbedding
7
+
8
+ class MultiHeadAttention(nn.Module):
9
+ """
10
+ Multi-Head Causal Self-Attention.
11
+ Uses scaled dot-product attention with causal masking.
12
+ """
13
+ def __init__(self, config: Dict[str, Any]):
14
+ super().__init__()
15
+ self.hidden_size = config.get("hidden_size", 512)
16
+ self.num_heads = config.get("num_attention_heads", 8)
17
+ self.head_dim = self.hidden_size // self.num_heads
18
+ self.dropout = config.get("attention_dropout", 0.0)
19
+ self.bias = config.get("bias", False)
20
+
21
+ if self.head_dim * self.num_heads != self.hidden_size:
22
+ raise ValueError(f"hidden_size ({self.hidden_size}) must be divisible by num_heads ({self.num_heads})")
23
+
24
+ # Linear projections
25
+ # We use separate linears for clarity, though combined QKV is slightly faster.
26
+ # Combined is fine, let's use separate for clean RoPE application.
27
+ self.q_proj = nn.Linear(self.hidden_size, self.hidden_size, bias=self.bias)
28
+ self.k_proj = nn.Linear(self.hidden_size, self.hidden_size, bias=self.bias)
29
+ self.v_proj = nn.Linear(self.hidden_size, self.hidden_size, bias=self.bias)
30
+ self.o_proj = nn.Linear(self.hidden_size, self.hidden_size, bias=self.bias)
31
+
32
+ self.attn_dropout = nn.Dropout(self.dropout)
33
+
34
+ def forward(self, x: torch.Tensor, rope: RotaryPositionalEmbedding) -> torch.Tensor:
35
+ """
36
+ Forward pass.
37
+ Args:
38
+ x: (B, T, D)
39
+ rope: RotaryPositionalEmbedding instance.
40
+ """
41
+ B, T, D = x.size()
42
+
43
+ # 1. Projections
44
+ q = self.q_proj(x) # (B, T, D)
45
+ k = self.k_proj(x) # (B, T, D)
46
+ v = self.v_proj(x) # (B, T, D)
47
+
48
+ # 2. Reshape to (B, H, T, HeadDim)
49
+ q = q.view(B, T, self.num_heads, self.head_dim).transpose(1, 2)
50
+ k = k.view(B, T, self.num_heads, self.head_dim).transpose(1, 2)
51
+ v = v.view(B, T, self.num_heads, self.head_dim).transpose(1, 2)
52
+
53
+ # 3. Apply RoPE to Query and Key
54
+ q, k = rope(q, k)
55
+
56
+ # 4. Scaled Dot-Product Attention
57
+ # scores: (B, H, T, T)
58
+ scores = torch.matmul(q, k.transpose(-2, -1)) / (self.head_dim ** 0.5)
59
+
60
+ # 5. Causal Mask
61
+ # We need a mask of shape (T, T) where upper triangle is -inf
62
+ mask = torch.triu(torch.ones(T, T, dtype=torch.bool, device=x.device), diagonal=1)
63
+ # Replace True with -inf
64
+ # Numerical safe masking
65
+ scores = scores.masked_fill(mask, float('-inf'))
66
+
67
+ # 6. Softmax
68
+ # fp32 is safer for softmax
69
+ probs = F.softmax(scores, dim=-1, dtype=torch.float32).to(q.dtype)
70
+ probs = self.attn_dropout(probs)
71
+
72
+ # 7. Weighted Sum
73
+ # out: (B, H, T, HeadDim)
74
+ out = torch.matmul(probs, v)
75
+
76
+ # 8. Merge Heads
77
+ # transpose back to (B, T, H, HeadDim) -> (B, T, D)
78
+ out = out.transpose(1, 2).contiguous().view(B, T, D)
79
+
80
+ # 9. Output Projection
81
+ return self.o_proj(out)