@r1z4x/tezgah 1.0.0
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.
- package/CHANGELOG.md +738 -0
- package/LICENSE +21 -0
- package/MANIFEST +753 -0
- package/README.de.md +169 -0
- package/README.es.md +168 -0
- package/README.fr.md +166 -0
- package/README.md +161 -0
- package/README.tr.md +163 -0
- package/agents/tezgah-reviewer.md +70 -0
- package/bin/codegen +337 -0
- package/bin/consult +797 -0
- package/bin/tezgah-adhd +50 -0
- package/bin/tezgah-agents +45 -0
- package/bin/tezgah-capture +66 -0
- package/bin/tezgah-context +96 -0
- package/bin/tezgah-decisions +213 -0
- package/bin/tezgah-design +953 -0
- package/bin/tezgah-docs +1199 -0
- package/bin/tezgah-doctor +497 -0
- package/bin/tezgah-dsh +37 -0
- package/bin/tezgah-dsh.cmd +70 -0
- package/bin/tezgah-gate +75 -0
- package/bin/tezgah-import-ai-research +439 -0
- package/bin/tezgah-index +32 -0
- package/bin/tezgah-lessons +148 -0
- package/bin/tezgah-mcp +322 -0
- package/bin/tezgah-migrate +324 -0
- package/bin/tezgah-pony +50 -0
- package/bin/tezgah-research +772 -0
- package/bin/tezgah-rollback +93 -0
- package/bin/tezgah-route +124 -0
- package/bin/tezgah-setup +5798 -0
- package/bin/tezgah-status +383 -0
- package/bin/tezgah-task +607 -0
- package/bin/tezgah-taste +423 -0
- package/bin/tezgah-triage +485 -0
- package/bin/tezgah.js +36 -0
- package/commands/adhd.md +21 -0
- package/commands/ponytail.md +21 -0
- package/docs/README.md +112 -0
- package/docs/architecture.md +226 -0
- package/docs/citations-baseline.json +59 -0
- package/docs/clarity-baseline.json +116 -0
- package/docs/contract.md +416 -0
- package/docs/environment.md +141 -0
- package/docs/evidence.md +831 -0
- package/docs/feature-audit.md +139 -0
- package/docs/gate.md +407 -0
- package/docs/glossary.md +201 -0
- package/docs/hosts.md +400 -0
- package/docs/index.json +471 -0
- package/docs/judge.md +193 -0
- package/docs/layers.md +189 -0
- package/docs/models.md +160 -0
- package/docs/operations.md +666 -0
- package/docs/research.md +809 -0
- package/docs/results/paired-outcome-2026-10.jsonl +254 -0
- package/docs/results/paired-outcome-2026-10.md +204 -0
- package/docs/skills.md +236 -0
- package/docs/status-line.md +315 -0
- package/docs/testing.md +287 -0
- package/docs/vision.md +117 -0
- package/hooks/hooks.json +33 -0
- package/hooks/projects-auto-init.py +98 -0
- package/hooks/projects-posttooluse.py +149 -0
- package/hooks/projects-pretooluse.py +40 -0
- package/hooks/projects-stop.py +60 -0
- package/hooks/tezgah_agents.py +817 -0
- package/hooks/tezgah_apps.py +266 -0
- package/hooks/tezgah_attest.py +255 -0
- package/hooks/tezgah_clarity.py +171 -0
- package/hooks/tezgah_components.py +140 -0
- package/hooks/tezgah_context.py +2953 -0
- package/hooks/tezgah_embed.py +765 -0
- package/hooks/tezgah_gate.py +2736 -0
- package/hooks/tezgah_guard.py +177 -0
- package/hooks/tezgah_index.py +124 -0
- package/hooks/tezgah_integrity.py +5141 -0
- package/hooks/tezgah_judge.py +487 -0
- package/hooks/tezgah_lang.py +230 -0
- package/hooks/tezgah_lessons.py +210 -0
- package/hooks/tezgah_models.py +855 -0
- package/hooks/tezgah_paths.py +1132 -0
- package/hooks/tezgah_policy.py +1039 -0
- package/hooks/tezgah_rank.py +77 -0
- package/hooks/tezgah_replay.py +1109 -0
- package/hooks/tezgah_research.py +5176 -0
- package/hooks/tezgah_shapes.py +305 -0
- package/hooks/tezgah_skill_pick.py +227 -0
- package/hooks/tezgah_snapshot.py +490 -0
- package/hooks/tezgah_stopspec.py +320 -0
- package/hooks/tezgah_task.py +458 -0
- package/hooks/tezgah_taste.py +201 -0
- package/hooks/tezgah_untrusted.py +112 -0
- package/hooks/tezgah_update.py +430 -0
- package/hosts/codex/hook.py +268 -0
- package/hosts/codex/hooks.json +26 -0
- package/hosts/cursor/hook.py +461 -0
- package/hosts/cursor/hooks.json +44 -0
- package/hosts/dsh/hooks.json +21 -0
- package/hosts/dsh/statusline/lib/client.js +138 -0
- package/hosts/dsh/statusline/lib/index.js +104 -0
- package/hosts/dsh/statusline/package.json +28 -0
- package/hosts/omp/hook.py +277 -0
- package/hosts/omp/tezgah-hook.ts.in +701 -0
- package/hosts/opencode/plugins/tezgah.js +2742 -0
- package/hosts/opencode/tui/tezgah-tui.tsx +151 -0
- package/output-styles/tezgah.md +142 -0
- package/package.json +32 -0
- package/packaging/build.sh +342 -0
- package/packaging/install.ps1 +166 -0
- package/packaging/install.sh +56 -0
- package/packaging/upgrade.sh +142 -0
- package/skills/ai-research/0-autoresearch-skill/SKILL.md +411 -0
- package/skills/ai-research/0-autoresearch-skill/references/agent-continuity.md +95 -0
- package/skills/ai-research/0-autoresearch-skill/references/progress-reporting.md +166 -0
- package/skills/ai-research/0-autoresearch-skill/references/skill-routing.md +219 -0
- package/skills/ai-research/0-autoresearch-skill/templates/findings.md +44 -0
- package/skills/ai-research/0-autoresearch-skill/templates/research-log.md +41 -0
- package/skills/ai-research/01-model-architecture/litgpt/SKILL.md +469 -0
- package/skills/ai-research/01-model-architecture/litgpt/references/custom-models.md +569 -0
- package/skills/ai-research/01-model-architecture/litgpt/references/distributed-training.md +452 -0
- package/skills/ai-research/01-model-architecture/litgpt/references/supported-models.md +337 -0
- package/skills/ai-research/01-model-architecture/litgpt/references/training-recipes.md +620 -0
- package/skills/ai-research/01-model-architecture/mamba/SKILL.md +260 -0
- package/skills/ai-research/01-model-architecture/mamba/references/architecture-details.md +207 -0
- package/skills/ai-research/01-model-architecture/mamba/references/benchmarks.md +256 -0
- package/skills/ai-research/01-model-architecture/mamba/references/training-guide.md +389 -0
- package/skills/ai-research/01-model-architecture/nanogpt/SKILL.md +290 -0
- package/skills/ai-research/01-model-architecture/nanogpt/references/architecture.md +383 -0
- package/skills/ai-research/01-model-architecture/nanogpt/references/data.md +477 -0
- package/skills/ai-research/01-model-architecture/nanogpt/references/training.md +565 -0
- package/skills/ai-research/01-model-architecture/rwkv/SKILL.md +260 -0
- package/skills/ai-research/01-model-architecture/rwkv/references/architecture-details.md +345 -0
- package/skills/ai-research/01-model-architecture/rwkv/references/rwkv7.md +387 -0
- package/skills/ai-research/01-model-architecture/rwkv/references/state-management.md +370 -0
- package/skills/ai-research/01-model-architecture/torchtitan/SKILL.md +358 -0
- package/skills/ai-research/01-model-architecture/torchtitan/references/checkpoint.md +182 -0
- package/skills/ai-research/01-model-architecture/torchtitan/references/custom-models.md +259 -0
- package/skills/ai-research/01-model-architecture/torchtitan/references/float8.md +134 -0
- package/skills/ai-research/01-model-architecture/torchtitan/references/fsdp.md +127 -0
- package/skills/ai-research/02-tokenization/huggingface-tokenizers/SKILL.md +516 -0
- package/skills/ai-research/02-tokenization/huggingface-tokenizers/references/algorithms.md +654 -0
- package/skills/ai-research/02-tokenization/huggingface-tokenizers/references/integration.md +638 -0
- package/skills/ai-research/02-tokenization/huggingface-tokenizers/references/pipeline.md +724 -0
- package/skills/ai-research/02-tokenization/huggingface-tokenizers/references/training.md +566 -0
- package/skills/ai-research/02-tokenization/sentencepiece/SKILL.md +235 -0
- package/skills/ai-research/02-tokenization/sentencepiece/references/algorithms.md +201 -0
- package/skills/ai-research/02-tokenization/sentencepiece/references/training.md +305 -0
- package/skills/ai-research/03-fine-tuning/axolotl/SKILL.md +158 -0
- package/skills/ai-research/03-fine-tuning/axolotl/references/api.md +5549 -0
- package/skills/ai-research/03-fine-tuning/axolotl/references/dataset-formats.md +1030 -0
- package/skills/ai-research/03-fine-tuning/axolotl/references/index.md +16 -0
- package/skills/ai-research/03-fine-tuning/axolotl/references/other.md +3564 -0
- package/skills/ai-research/03-fine-tuning/llama-factory/SKILL.md +80 -0
- package/skills/ai-research/03-fine-tuning/llama-factory/references/_images.md +24 -0
- package/skills/ai-research/03-fine-tuning/llama-factory/references/advanced.md +1056 -0
- package/skills/ai-research/03-fine-tuning/llama-factory/references/getting_started.md +350 -0
- package/skills/ai-research/03-fine-tuning/llama-factory/references/index.md +20 -0
- package/skills/ai-research/03-fine-tuning/llama-factory/references/other.md +32 -0
- package/skills/ai-research/03-fine-tuning/peft/SKILL.md +431 -0
- package/skills/ai-research/03-fine-tuning/peft/references/advanced-usage.md +515 -0
- package/skills/ai-research/03-fine-tuning/peft/references/troubleshooting.md +481 -0
- package/skills/ai-research/03-fine-tuning/unsloth/SKILL.md +80 -0
- package/skills/ai-research/03-fine-tuning/unsloth/references/index.md +8 -0
- package/skills/ai-research/03-fine-tuning/unsloth/references/llms.md +83 -0
- package/skills/ai-research/04-mechanistic-interpretability/nnsight/SKILL.md +436 -0
- package/skills/ai-research/04-mechanistic-interpretability/nnsight/references/README.md +79 -0
- package/skills/ai-research/04-mechanistic-interpretability/nnsight/references/api.md +345 -0
- package/skills/ai-research/04-mechanistic-interpretability/nnsight/references/tutorials.md +301 -0
- package/skills/ai-research/04-mechanistic-interpretability/pyvene/SKILL.md +473 -0
- package/skills/ai-research/04-mechanistic-interpretability/pyvene/references/README.md +74 -0
- package/skills/ai-research/04-mechanistic-interpretability/pyvene/references/api.md +384 -0
- package/skills/ai-research/04-mechanistic-interpretability/pyvene/references/tutorials.md +377 -0
- package/skills/ai-research/04-mechanistic-interpretability/saelens/SKILL.md +386 -0
- package/skills/ai-research/04-mechanistic-interpretability/saelens/references/README.md +71 -0
- package/skills/ai-research/04-mechanistic-interpretability/saelens/references/api.md +334 -0
- package/skills/ai-research/04-mechanistic-interpretability/saelens/references/tutorials.md +319 -0
- package/skills/ai-research/04-mechanistic-interpretability/transformer-lens/SKILL.md +346 -0
- package/skills/ai-research/04-mechanistic-interpretability/transformer-lens/references/README.md +55 -0
- package/skills/ai-research/04-mechanistic-interpretability/transformer-lens/references/api.md +363 -0
- package/skills/ai-research/04-mechanistic-interpretability/transformer-lens/references/tutorials.md +340 -0
- package/skills/ai-research/05-data-processing/nemo-curator/SKILL.md +383 -0
- package/skills/ai-research/05-data-processing/nemo-curator/references/deduplication.md +88 -0
- package/skills/ai-research/05-data-processing/nemo-curator/references/filtering.md +103 -0
- package/skills/ai-research/05-data-processing/ray-data/SKILL.md +326 -0
- package/skills/ai-research/05-data-processing/ray-data/references/integration.md +83 -0
- package/skills/ai-research/05-data-processing/ray-data/references/transformations.md +84 -0
- package/skills/ai-research/06-post-training/grpo-rl-training/README.md +98 -0
- package/skills/ai-research/06-post-training/grpo-rl-training/SKILL.md +572 -0
- package/skills/ai-research/06-post-training/miles/SKILL.md +315 -0
- package/skills/ai-research/06-post-training/miles/references/api-reference.md +142 -0
- package/skills/ai-research/06-post-training/miles/references/troubleshooting.md +353 -0
- package/skills/ai-research/06-post-training/openrlhf/SKILL.md +249 -0
- package/skills/ai-research/06-post-training/openrlhf/references/algorithm-comparison.md +405 -0
- package/skills/ai-research/06-post-training/openrlhf/references/custom-rewards.md +531 -0
- package/skills/ai-research/06-post-training/openrlhf/references/hybrid-engine.md +288 -0
- package/skills/ai-research/06-post-training/openrlhf/references/multi-node-training.md +455 -0
- package/skills/ai-research/06-post-training/simpo/SKILL.md +219 -0
- package/skills/ai-research/06-post-training/simpo/references/datasets.md +479 -0
- package/skills/ai-research/06-post-training/simpo/references/hyperparameters.md +453 -0
- package/skills/ai-research/06-post-training/simpo/references/loss-functions.md +351 -0
- package/skills/ai-research/06-post-training/slime/SKILL.md +464 -0
- package/skills/ai-research/06-post-training/slime/references/api-reference.md +393 -0
- package/skills/ai-research/06-post-training/slime/references/troubleshooting.md +387 -0
- package/skills/ai-research/06-post-training/torchforge/SKILL.md +433 -0
- package/skills/ai-research/06-post-training/torchforge/references/api-reference.md +328 -0
- package/skills/ai-research/06-post-training/torchforge/references/troubleshooting.md +410 -0
- package/skills/ai-research/06-post-training/trl-fine-tuning/SKILL.md +455 -0
- package/skills/ai-research/06-post-training/trl-fine-tuning/references/dpo-variants.md +228 -0
- package/skills/ai-research/06-post-training/trl-fine-tuning/references/online-rl.md +83 -0
- package/skills/ai-research/06-post-training/trl-fine-tuning/references/reward-modeling.md +123 -0
- package/skills/ai-research/06-post-training/trl-fine-tuning/references/sft-training.md +169 -0
- package/skills/ai-research/06-post-training/verl/SKILL.md +391 -0
- package/skills/ai-research/06-post-training/verl/references/api-reference.md +302 -0
- package/skills/ai-research/06-post-training/verl/references/troubleshooting.md +392 -0
- package/skills/ai-research/07-safety-alignment/constitutional-ai/SKILL.md +290 -0
- package/skills/ai-research/07-safety-alignment/llamaguard/SKILL.md +337 -0
- package/skills/ai-research/07-safety-alignment/nemo-guardrails/SKILL.md +297 -0
- package/skills/ai-research/07-safety-alignment/prompt-guard/SKILL.md +312 -0
- package/skills/ai-research/08-distributed-training/accelerate/SKILL.md +332 -0
- package/skills/ai-research/08-distributed-training/accelerate/references/custom-plugins.md +454 -0
- package/skills/ai-research/08-distributed-training/accelerate/references/megatron-integration.md +490 -0
- package/skills/ai-research/08-distributed-training/accelerate/references/performance.md +526 -0
- package/skills/ai-research/08-distributed-training/deepspeed/SKILL.md +141 -0
- package/skills/ai-research/08-distributed-training/deepspeed/references/08.md +18 -0
- package/skills/ai-research/08-distributed-training/deepspeed/references/09.md +174 -0
- package/skills/ai-research/08-distributed-training/deepspeed/references/2020.md +379 -0
- package/skills/ai-research/08-distributed-training/deepspeed/references/2023.md +280 -0
- package/skills/ai-research/08-distributed-training/deepspeed/references/assets.md +180 -0
- package/skills/ai-research/08-distributed-training/deepspeed/references/index.md +36 -0
- package/skills/ai-research/08-distributed-training/deepspeed/references/mii.md +119 -0
- package/skills/ai-research/08-distributed-training/deepspeed/references/other.md +1192 -0
- package/skills/ai-research/08-distributed-training/megatron-core/SKILL.md +366 -0
- package/skills/ai-research/08-distributed-training/megatron-core/references/benchmarks.md +250 -0
- package/skills/ai-research/08-distributed-training/megatron-core/references/parallelism-guide.md +405 -0
- package/skills/ai-research/08-distributed-training/megatron-core/references/production-examples.md +474 -0
- package/skills/ai-research/08-distributed-training/megatron-core/references/training-recipes.md +548 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/SKILL.md +231 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_dcp_async_recipe.md +14 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_dcp_overview.md +19 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_dcp_recipe.md +18 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_ddp_notes.md +10 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_device_mesh_tutorial.md +22 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_examples_fsdp2.md +15 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_fsdp1_api.md +9 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_fsdp2_tutorial.md +45 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_fully_shard_api.md +49 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/pytorch_tp_tutorial.md +22 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/ray_train_fsdp2_example.md +13 -0
- package/skills/ai-research/08-distributed-training/pytorch-fsdp2/references/torchtitan_fsdp_notes.md +14 -0
- package/skills/ai-research/08-distributed-training/pytorch-lightning/SKILL.md +346 -0
- package/skills/ai-research/08-distributed-training/pytorch-lightning/references/callbacks.md +437 -0
- package/skills/ai-research/08-distributed-training/pytorch-lightning/references/distributed.md +491 -0
- package/skills/ai-research/08-distributed-training/pytorch-lightning/references/hyperparameter-tuning.md +557 -0
- package/skills/ai-research/08-distributed-training/ray-train/SKILL.md +406 -0
- package/skills/ai-research/08-distributed-training/ray-train/references/multi-node.md +629 -0
- package/skills/ai-research/09-infrastructure/lambda-labs/SKILL.md +545 -0
- package/skills/ai-research/09-infrastructure/lambda-labs/references/advanced-usage.md +612 -0
- package/skills/ai-research/09-infrastructure/lambda-labs/references/troubleshooting.md +531 -0
- package/skills/ai-research/09-infrastructure/modal/SKILL.md +341 -0
- package/skills/ai-research/09-infrastructure/modal/references/advanced-usage.md +504 -0
- package/skills/ai-research/09-infrastructure/modal/references/troubleshooting.md +495 -0
- package/skills/ai-research/09-infrastructure/skypilot/SKILL.md +509 -0
- package/skills/ai-research/09-infrastructure/skypilot/references/advanced-usage.md +492 -0
- package/skills/ai-research/09-infrastructure/skypilot/references/troubleshooting.md +571 -0
- package/skills/ai-research/10-optimization/awq/SKILL.md +310 -0
- package/skills/ai-research/10-optimization/awq/references/advanced-usage.md +325 -0
- package/skills/ai-research/10-optimization/awq/references/troubleshooting.md +345 -0
- package/skills/ai-research/10-optimization/bitsandbytes/SKILL.md +411 -0
- package/skills/ai-research/10-optimization/bitsandbytes/references/memory-optimization.md +522 -0
- package/skills/ai-research/10-optimization/bitsandbytes/references/qlora-training.md +522 -0
- package/skills/ai-research/10-optimization/bitsandbytes/references/quantization-formats.md +448 -0
- package/skills/ai-research/10-optimization/flash-attention/SKILL.md +367 -0
- package/skills/ai-research/10-optimization/flash-attention/references/benchmarks.md +216 -0
- package/skills/ai-research/10-optimization/flash-attention/references/transformers-integration.md +294 -0
- package/skills/ai-research/10-optimization/gguf/SKILL.md +427 -0
- package/skills/ai-research/10-optimization/gguf/references/advanced-usage.md +505 -0
- package/skills/ai-research/10-optimization/gguf/references/troubleshooting.md +443 -0
- package/skills/ai-research/10-optimization/gptq/SKILL.md +450 -0
- package/skills/ai-research/10-optimization/gptq/references/calibration.md +338 -0
- package/skills/ai-research/10-optimization/gptq/references/integration.md +130 -0
- package/skills/ai-research/10-optimization/gptq/references/troubleshooting.md +96 -0
- package/skills/ai-research/10-optimization/hqq/SKILL.md +445 -0
- package/skills/ai-research/10-optimization/hqq/references/advanced-usage.md +529 -0
- package/skills/ai-research/10-optimization/hqq/references/troubleshooting.md +504 -0
- package/skills/ai-research/10-optimization/ml-training-recipes/SKILL.md +319 -0
- package/skills/ai-research/10-optimization/ml-training-recipes/references/architecture.md +320 -0
- package/skills/ai-research/10-optimization/ml-training-recipes/references/biomedical.md +498 -0
- package/skills/ai-research/10-optimization/ml-training-recipes/references/domain-specific.md +626 -0
- package/skills/ai-research/10-optimization/ml-training-recipes/references/experiment-loop.md +129 -0
- package/skills/ai-research/10-optimization/ml-training-recipes/references/optimizers.md +330 -0
- package/skills/ai-research/10-optimization/ml-training-recipes/references/scaling-and-selection.md +428 -0
- package/skills/ai-research/11-evaluation/bigcode-evaluation-harness/SKILL.md +405 -0
- package/skills/ai-research/11-evaluation/bigcode-evaluation-harness/references/benchmarks.md +394 -0
- package/skills/ai-research/11-evaluation/bigcode-evaluation-harness/references/custom-tasks.md +425 -0
- package/skills/ai-research/11-evaluation/bigcode-evaluation-harness/references/issues.md +395 -0
- package/skills/ai-research/11-evaluation/lm-evaluation-harness/SKILL.md +490 -0
- package/skills/ai-research/11-evaluation/lm-evaluation-harness/references/api-evaluation.md +491 -0
- package/skills/ai-research/11-evaluation/lm-evaluation-harness/references/benchmark-guide.md +489 -0
- package/skills/ai-research/11-evaluation/lm-evaluation-harness/references/custom-tasks.md +603 -0
- package/skills/ai-research/11-evaluation/lm-evaluation-harness/references/distributed-eval.md +520 -0
- package/skills/ai-research/11-evaluation/nemo-evaluator/SKILL.md +494 -0
- package/skills/ai-research/11-evaluation/nemo-evaluator/references/adapter-system.md +341 -0
- package/skills/ai-research/11-evaluation/nemo-evaluator/references/configuration.md +448 -0
- package/skills/ai-research/11-evaluation/nemo-evaluator/references/custom-benchmarks.md +316 -0
- package/skills/ai-research/11-evaluation/nemo-evaluator/references/execution-backends.md +362 -0
- package/skills/ai-research/12-inference-serving/llama-cpp/SKILL.md +258 -0
- package/skills/ai-research/12-inference-serving/llama-cpp/references/optimization.md +90 -0
- package/skills/ai-research/12-inference-serving/llama-cpp/references/quantization.md +214 -0
- package/skills/ai-research/12-inference-serving/llama-cpp/references/server.md +126 -0
- package/skills/ai-research/12-inference-serving/sglang/SKILL.md +442 -0
- package/skills/ai-research/12-inference-serving/sglang/references/deployment.md +491 -0
- package/skills/ai-research/12-inference-serving/sglang/references/radix-attention.md +414 -0
- package/skills/ai-research/12-inference-serving/sglang/references/structured-generation.md +542 -0
- package/skills/ai-research/12-inference-serving/tensorrt-llm/SKILL.md +187 -0
- package/skills/ai-research/12-inference-serving/tensorrt-llm/references/multi-gpu.md +299 -0
- package/skills/ai-research/12-inference-serving/tensorrt-llm/references/optimization.md +243 -0
- package/skills/ai-research/12-inference-serving/tensorrt-llm/references/serving.md +471 -0
- package/skills/ai-research/12-inference-serving/vllm/SKILL.md +364 -0
- package/skills/ai-research/12-inference-serving/vllm/references/optimization.md +227 -0
- package/skills/ai-research/12-inference-serving/vllm/references/quantization.md +285 -0
- package/skills/ai-research/12-inference-serving/vllm/references/server-deployment.md +256 -0
- package/skills/ai-research/12-inference-serving/vllm/references/troubleshooting.md +448 -0
- package/skills/ai-research/13-mlops/mlflow/SKILL.md +704 -0
- package/skills/ai-research/13-mlops/mlflow/references/deployment.md +745 -0
- package/skills/ai-research/13-mlops/mlflow/references/model-registry.md +771 -0
- package/skills/ai-research/13-mlops/mlflow/references/tracking.md +681 -0
- package/skills/ai-research/13-mlops/swanlab/SKILL.md +406 -0
- package/skills/ai-research/13-mlops/swanlab/references/integrations.md +305 -0
- package/skills/ai-research/13-mlops/swanlab/references/visualization.md +234 -0
- package/skills/ai-research/13-mlops/tensorboard/SKILL.md +629 -0
- package/skills/ai-research/13-mlops/tensorboard/references/integrations.md +639 -0
- package/skills/ai-research/13-mlops/tensorboard/references/profiling.md +546 -0
- package/skills/ai-research/13-mlops/tensorboard/references/visualization.md +621 -0
- package/skills/ai-research/13-mlops/weights-and-biases/SKILL.md +590 -0
- package/skills/ai-research/13-mlops/weights-and-biases/references/artifacts.md +585 -0
- package/skills/ai-research/13-mlops/weights-and-biases/references/integrations.md +701 -0
- package/skills/ai-research/13-mlops/weights-and-biases/references/sweeps.md +848 -0
- package/skills/ai-research/14-agents/a-evolve/SKILL.md +383 -0
- package/skills/ai-research/14-agents/a-evolve/references/README.md +831 -0
- package/skills/ai-research/14-agents/a-evolve/references/api.md +594 -0
- package/skills/ai-research/14-agents/a-evolve/references/architecture.md +417 -0
- package/skills/ai-research/14-agents/a-evolve/references/design-patterns.md +462 -0
- package/skills/ai-research/14-agents/a-evolve/references/examples.md +352 -0
- package/skills/ai-research/14-agents/a-evolve/references/issues.md +591 -0
- package/skills/ai-research/14-agents/a-evolve/references/releases.md +112 -0
- package/skills/ai-research/14-agents/a-evolve/references/tutorials.md +819 -0
- package/skills/ai-research/14-agents/autogpt/SKILL.md +403 -0
- package/skills/ai-research/14-agents/autogpt/references/advanced-usage.md +536 -0
- package/skills/ai-research/14-agents/autogpt/references/troubleshooting.md +421 -0
- package/skills/ai-research/14-agents/crewai/SKILL.md +498 -0
- package/skills/ai-research/14-agents/crewai/references/flows.md +439 -0
- package/skills/ai-research/14-agents/crewai/references/tools.md +430 -0
- package/skills/ai-research/14-agents/crewai/references/troubleshooting.md +481 -0
- package/skills/ai-research/14-agents/langchain/SKILL.md +480 -0
- package/skills/ai-research/14-agents/langchain/references/agents.md +500 -0
- package/skills/ai-research/14-agents/langchain/references/integration.md +563 -0
- package/skills/ai-research/14-agents/langchain/references/rag.md +601 -0
- package/skills/ai-research/14-agents/llamaindex/SKILL.md +569 -0
- package/skills/ai-research/14-agents/llamaindex/references/agents.md +84 -0
- package/skills/ai-research/14-agents/llamaindex/references/data_connectors.md +109 -0
- package/skills/ai-research/14-agents/llamaindex/references/query_engines.md +407 -0
- package/skills/ai-research/15-rag/chroma/SKILL.md +406 -0
- package/skills/ai-research/15-rag/chroma/references/integration.md +39 -0
- package/skills/ai-research/15-rag/faiss/SKILL.md +221 -0
- package/skills/ai-research/15-rag/faiss/references/index_types.md +281 -0
- package/skills/ai-research/15-rag/pinecone/SKILL.md +358 -0
- package/skills/ai-research/15-rag/pinecone/references/deployment.md +182 -0
- package/skills/ai-research/15-rag/qdrant/SKILL.md +493 -0
- package/skills/ai-research/15-rag/qdrant/references/advanced-usage.md +649 -0
- package/skills/ai-research/15-rag/qdrant/references/troubleshooting.md +632 -0
- package/skills/ai-research/15-rag/sentence-transformers/SKILL.md +255 -0
- package/skills/ai-research/15-rag/sentence-transformers/references/models.md +124 -0
- package/skills/ai-research/16-prompt-engineering/dspy/SKILL.md +590 -0
- package/skills/ai-research/16-prompt-engineering/dspy/references/examples.md +664 -0
- package/skills/ai-research/16-prompt-engineering/dspy/references/modules.md +476 -0
- package/skills/ai-research/16-prompt-engineering/dspy/references/optimizers.md +567 -0
- package/skills/ai-research/16-prompt-engineering/guidance/SKILL.md +572 -0
- package/skills/ai-research/16-prompt-engineering/guidance/references/backends.md +555 -0
- package/skills/ai-research/16-prompt-engineering/guidance/references/constraints.md +675 -0
- package/skills/ai-research/16-prompt-engineering/guidance/references/examples.md +768 -0
- package/skills/ai-research/16-prompt-engineering/instructor/SKILL.md +740 -0
- package/skills/ai-research/16-prompt-engineering/instructor/references/examples.md +108 -0
- package/skills/ai-research/16-prompt-engineering/instructor/references/providers.md +71 -0
- package/skills/ai-research/16-prompt-engineering/instructor/references/validation.md +607 -0
- package/skills/ai-research/16-prompt-engineering/outlines/SKILL.md +652 -0
- package/skills/ai-research/16-prompt-engineering/outlines/references/backends.md +616 -0
- package/skills/ai-research/16-prompt-engineering/outlines/references/examples.md +774 -0
- package/skills/ai-research/16-prompt-engineering/outlines/references/json_generation.md +653 -0
- package/skills/ai-research/17-observability/langsmith/SKILL.md +422 -0
- package/skills/ai-research/17-observability/langsmith/references/advanced-usage.md +549 -0
- package/skills/ai-research/17-observability/langsmith/references/troubleshooting.md +538 -0
- package/skills/ai-research/17-observability/phoenix/SKILL.md +475 -0
- package/skills/ai-research/17-observability/phoenix/references/advanced-usage.md +620 -0
- package/skills/ai-research/17-observability/phoenix/references/troubleshooting.md +539 -0
- package/skills/ai-research/18-multimodal/audiocraft/SKILL.md +564 -0
- package/skills/ai-research/18-multimodal/audiocraft/references/advanced-usage.md +667 -0
- package/skills/ai-research/18-multimodal/audiocraft/references/troubleshooting.md +505 -0
- package/skills/ai-research/18-multimodal/blip-2/SKILL.md +564 -0
- package/skills/ai-research/18-multimodal/blip-2/references/advanced-usage.md +681 -0
- package/skills/ai-research/18-multimodal/blip-2/references/troubleshooting.md +527 -0
- package/skills/ai-research/18-multimodal/clip/SKILL.md +253 -0
- package/skills/ai-research/18-multimodal/clip/references/applications.md +208 -0
- package/skills/ai-research/18-multimodal/cosmos-policy/SKILL.md +402 -0
- package/skills/ai-research/18-multimodal/cosmos-policy/references/libero-commands.md +175 -0
- package/skills/ai-research/18-multimodal/cosmos-policy/references/robocasa-commands.md +147 -0
- package/skills/ai-research/18-multimodal/llava/SKILL.md +304 -0
- package/skills/ai-research/18-multimodal/llava/references/training.md +198 -0
- package/skills/ai-research/18-multimodal/openpi/SKILL.md +480 -0
- package/skills/ai-research/18-multimodal/openpi/references/checkpoints-and-env-map.md +86 -0
- package/skills/ai-research/18-multimodal/openpi/references/config-recipes.md +50 -0
- package/skills/ai-research/18-multimodal/openpi/references/pytorch-gotchas.md +49 -0
- package/skills/ai-research/18-multimodal/openpi/references/remote-client-pattern.md +48 -0
- package/skills/ai-research/18-multimodal/openpi/references/training-debugging.md +46 -0
- package/skills/ai-research/18-multimodal/openvla-oft/SKILL.md +441 -0
- package/skills/ai-research/18-multimodal/openvla-oft/references/aloha-workflow.md +141 -0
- package/skills/ai-research/18-multimodal/openvla-oft/references/config-troubleshooting.md +97 -0
- package/skills/ai-research/18-multimodal/openvla-oft/references/libero-workflow.md +115 -0
- package/skills/ai-research/18-multimodal/openvla-oft/references/paper-and-checkpoints.md +84 -0
- package/skills/ai-research/18-multimodal/segment-anything/SKILL.md +500 -0
- package/skills/ai-research/18-multimodal/segment-anything/references/advanced-usage.md +590 -0
- package/skills/ai-research/18-multimodal/segment-anything/references/troubleshooting.md +485 -0
- package/skills/ai-research/18-multimodal/stable-diffusion/SKILL.md +519 -0
- package/skills/ai-research/18-multimodal/stable-diffusion/references/advanced-usage.md +717 -0
- package/skills/ai-research/18-multimodal/stable-diffusion/references/troubleshooting.md +556 -0
- package/skills/ai-research/18-multimodal/whisper/SKILL.md +317 -0
- package/skills/ai-research/18-multimodal/whisper/references/languages.md +190 -0
- package/skills/ai-research/19-emerging-techniques/knowledge-distillation/SKILL.md +458 -0
- package/skills/ai-research/19-emerging-techniques/knowledge-distillation/references/minillm.md +335 -0
- package/skills/ai-research/19-emerging-techniques/long-context/SKILL.md +536 -0
- package/skills/ai-research/19-emerging-techniques/long-context/references/extension_methods.md +469 -0
- package/skills/ai-research/19-emerging-techniques/long-context/references/fine_tuning.md +612 -0
- package/skills/ai-research/19-emerging-techniques/long-context/references/rope.md +403 -0
- package/skills/ai-research/19-emerging-techniques/model-merging/SKILL.md +497 -0
- package/skills/ai-research/19-emerging-techniques/model-merging/references/coefficient-tuning.md +415 -0
- package/skills/ai-research/19-emerging-techniques/model-merging/references/evaluation.md +463 -0
- package/skills/ai-research/19-emerging-techniques/model-merging/references/examples.md +429 -0
- package/skills/ai-research/19-emerging-techniques/model-merging/references/methods.md +353 -0
- package/skills/ai-research/19-emerging-techniques/model-pruning/SKILL.md +495 -0
- package/skills/ai-research/19-emerging-techniques/model-pruning/references/wanda.md +348 -0
- package/skills/ai-research/19-emerging-techniques/moe-training/SKILL.md +526 -0
- package/skills/ai-research/19-emerging-techniques/moe-training/references/architectures.md +433 -0
- package/skills/ai-research/19-emerging-techniques/moe-training/references/inference.md +349 -0
- package/skills/ai-research/19-emerging-techniques/moe-training/references/training.md +426 -0
- package/skills/ai-research/19-emerging-techniques/speculative-decoding/SKILL.md +467 -0
- package/skills/ai-research/19-emerging-techniques/speculative-decoding/references/lookahead.md +310 -0
- package/skills/ai-research/19-emerging-techniques/speculative-decoding/references/medusa.md +351 -0
- package/skills/ai-research/20-ml-paper-writing/academic-plotting/SKILL.md +479 -0
- package/skills/ai-research/20-ml-paper-writing/academic-plotting/references/data-visualization.md +509 -0
- package/skills/ai-research/20-ml-paper-writing/academic-plotting/references/diagram-generation.md +395 -0
- package/skills/ai-research/20-ml-paper-writing/academic-plotting/references/style-guide.md +305 -0
- package/skills/ai-research/20-ml-paper-writing/ml-paper-writing/SKILL.md +982 -0
- package/skills/ai-research/20-ml-paper-writing/ml-paper-writing/references/checklists.md +348 -0
- package/skills/ai-research/20-ml-paper-writing/ml-paper-writing/references/citation-workflow.md +563 -0
- package/skills/ai-research/20-ml-paper-writing/ml-paper-writing/references/reviewer-guidelines.md +349 -0
- package/skills/ai-research/20-ml-paper-writing/ml-paper-writing/references/sources.md +165 -0
- package/skills/ai-research/20-ml-paper-writing/ml-paper-writing/references/writing-guide.md +477 -0
- package/skills/ai-research/20-ml-paper-writing/presenting-conference-talks/SKILL.md +298 -0
- package/skills/ai-research/20-ml-paper-writing/presenting-conference-talks/references/slide-templates.md +505 -0
- package/skills/ai-research/20-ml-paper-writing/systems-paper-writing/SKILL.md +270 -0
- package/skills/ai-research/20-ml-paper-writing/systems-paper-writing/references/checklist.md +279 -0
- package/skills/ai-research/20-ml-paper-writing/systems-paper-writing/references/reviewer-guidelines.md +116 -0
- package/skills/ai-research/20-ml-paper-writing/systems-paper-writing/references/section-blueprints.md +400 -0
- package/skills/ai-research/20-ml-paper-writing/systems-paper-writing/references/systems-conferences.md +261 -0
- package/skills/ai-research/20-ml-paper-writing/systems-paper-writing/references/writing-patterns.md +231 -0
- package/skills/ai-research/21-research-ideation/brainstorming-research-ideas/SKILL.md +384 -0
- package/skills/ai-research/21-research-ideation/creative-thinking-for-research/SKILL.md +366 -0
- package/skills/ai-research/22-agent-native-research-artifact/compiler/SKILL.md +245 -0
- package/skills/ai-research/22-agent-native-research-artifact/compiler/references/ara-schema.md +439 -0
- package/skills/ai-research/22-agent-native-research-artifact/compiler/references/exploration-tree-spec.md +125 -0
- package/skills/ai-research/22-agent-native-research-artifact/compiler/references/validation-checklist.md +149 -0
- package/skills/ai-research/22-agent-native-research-artifact/research-manager/SKILL.md +324 -0
- package/skills/ai-research/22-agent-native-research-artifact/research-manager/references/event-taxonomy.md +124 -0
- package/skills/ai-research/22-agent-native-research-artifact/research-manager/references/provenance-tags.md +190 -0
- package/skills/ai-research/22-agent-native-research-artifact/research-manager/references/session-protocol.md +162 -0
- package/skills/ai-research/22-agent-native-research-artifact/rigor-reviewer/SKILL.md +322 -0
- package/skills/ai-research/22-agent-native-research-artifact/rigor-reviewer/references/review-dimensions.md +182 -0
- package/skills/ai-research/SKILL.md +101 -0
- package/skills/ai-research/SOURCE +38 -0
- package/skills/ai-research/index/1-frame.md +18 -0
- package/skills/ai-research/index/2-data.md +21 -0
- package/skills/ai-research/index/3-train.md +48 -0
- package/skills/ai-research/index/4-measure.md +25 -0
- package/skills/ai-research/index/5-run.md +23 -0
- package/skills/ai-research/index/6-write.md +35 -0
- package/skills/ai-research/library.json +3456 -0
- package/skills/analyze-app/EVALS.md +82 -0
- package/skills/analyze-app/SKILL.md +188 -0
- package/skills/design-contract/EVALS.md +80 -0
- package/skills/design-contract/SKILL.md +171 -0
- package/skills/design-library/EVALS.md +85 -0
- package/skills/design-library/INDEX.md +59 -0
- package/skills/design-library/SKILL.md +58 -0
- package/skills/design-library/SOURCE +131 -0
- package/skills/design-library/adaptive-interfaces/skills/colour-independence/SKILL.md +90 -0
- package/skills/design-library/adaptive-interfaces/skills/flexible-typography/SKILL.md +83 -0
- package/skills/design-library/adaptive-interfaces/skills/information-density/SKILL.md +87 -0
- package/skills/design-library/adaptive-interfaces/skills/preference-audit/SKILL.md +70 -0
- package/skills/design-library/adaptive-interfaces/skills/responsive-accessibility/SKILL.md +86 -0
- package/skills/design-library/adaptive-interfaces/skills/responsive-review/SKILL.md +76 -0
- package/skills/design-library/adaptive-interfaces/skills/simplified-views/SKILL.md +97 -0
- package/skills/design-library/adaptive-interfaces/skills/specify/SKILL.md +63 -0
- package/skills/design-library/adaptive-interfaces/skills/user-preference-respect/SKILL.md +100 -0
- package/skills/design-library/cognitive-accessibility/skills/adaptive-personalisation/SKILL.md +61 -0
- package/skills/design-library/cognitive-accessibility/skills/assess-load/SKILL.md +48 -0
- package/skills/design-library/cognitive-accessibility/skills/cognitive-load-assessment/SKILL.md +60 -0
- package/skills/design-library/cognitive-accessibility/skills/contextual-help-design/SKILL.md +61 -0
- package/skills/design-library/cognitive-accessibility/skills/error-prevention-recovery/SKILL.md +71 -0
- package/skills/design-library/cognitive-accessibility/skills/focus-attention-design/SKILL.md +67 -0
- package/skills/design-library/cognitive-accessibility/skills/memory-load-reduction/SKILL.md +60 -0
- package/skills/design-library/cognitive-accessibility/skills/plain-language-design/SKILL.md +78 -0
- package/skills/design-library/cognitive-accessibility/skills/review/SKILL.md +56 -0
- package/skills/design-library/cognitive-accessibility/skills/simplify/SKILL.md +39 -0
- package/skills/design-library/cognitive-accessibility/skills/wayfinding-navigation/SKILL.md +64 -0
- package/skills/design-library/design-research/skills/behavioural-analytics/SKILL.md +33 -0
- package/skills/design-library/design-research/skills/qual-quant-triangulation/SKILL.md +33 -0
- package/skills/design-library/inclusive-interaction/skills/audit/SKILL.md +50 -0
- package/skills/design-library/inclusive-interaction/skills/design-flow/SKILL.md +58 -0
- package/skills/design-library/inclusive-interaction/skills/feedback-and-status/SKILL.md +76 -0
- package/skills/design-library/inclusive-interaction/skills/gesture-alternatives/SKILL.md +70 -0
- package/skills/design-library/inclusive-interaction/skills/keyboard-navigation/SKILL.md +99 -0
- package/skills/design-library/inclusive-interaction/skills/keyboard-review/SKILL.md +54 -0
- package/skills/design-library/inclusive-interaction/skills/motion-sensitivity/SKILL.md +79 -0
- package/skills/design-library/inclusive-interaction/skills/multi-modal-input/SKILL.md +70 -0
- package/skills/design-library/inclusive-interaction/skills/touch-target-design/SKILL.md +71 -0
- package/skills/design-library/inclusive-interaction/skills/voice-interaction/SKILL.md +68 -0
- package/skills/design-library/visual-critique/skills/critique-affordance/SKILL.md +45 -0
- package/skills/design-library/visual-critique/skills/critique-brand-consistency/SKILL.md +42 -0
- package/skills/design-library/visual-critique/skills/critique-color/SKILL.md +44 -0
- package/skills/design-library/visual-critique/skills/critique-composition/SKILL.md +46 -0
- package/skills/design-library/visual-critique/skills/critique-information-density/SKILL.md +45 -0
- package/skills/design-library/visual-critique/skills/critique-typography/SKILL.md +45 -0
- package/skills/design-library/visual-critique/skills/critique-visual-hierarchy/SKILL.md +40 -0
- package/skills/feature-audit/EVALS.md +83 -0
- package/skills/feature-audit/SKILL.md +326 -0
- package/skills/harness/EVALS.md +81 -0
- package/skills/harness/SKILL.md +88 -0
- package/skills/i-have-adhd/EVALS.md +80 -0
- package/skills/i-have-adhd/SKILL.md +183 -0
- package/skills/no-ai-slop/EVALS.md +89 -0
- package/skills/no-ai-slop/SKILL.md +209 -0
- package/skills/no-ai-slop/eval.md +52 -0
- package/skills/plan-add/EVALS.md +79 -0
- package/skills/plan-add/SKILL.md +179 -0
- package/skills/plan-add/render_table.py +72 -0
- package/skills/plan-status/EVALS.md +78 -0
- package/skills/plan-status/SKILL.md +52 -0
- package/skills/plan-sync/EVALS.md +80 -0
- package/skills/plan-sync/SKILL.md +69 -0
- package/skills/pm-frameworks/SKILL.md +33 -0
- package/skills/pm-frameworks/SOURCE +39 -0
- package/skills/pm-frameworks/intended-vs-implemented/SKILL.md +42 -0
- package/skills/pm-frameworks/opportunity-solution-tree/SKILL.md +64 -0
- package/skills/ponytail/EVALS.md +80 -0
- package/skills/ponytail/SKILL.md +124 -0
- package/skills/product-analysis/EVALS.md +103 -0
- package/skills/product-analysis/SKILL.md +361 -0
- package/skills/research/EVALS.md +104 -0
- package/skills/research/SKILL.md +570 -0
- package/skills/rl-env/SKILL.md +53 -0
- package/skills/rl-env/SOURCE +41 -0
- package/skills/rl-env/generate-nemo-gym-env/SKILL.md +169 -0
- package/skills/rl-env/generate-nemo-gym-env/references/architecture.md +114 -0
- package/skills/rl-env/generate-openenv-env/SKILL.md +183 -0
- package/skills/rl-env/generate-openenv-env/references/architecture.md +82 -0
- package/skills/rl-env/generate-ors-env/SKILL.md +209 -0
- package/skills/rl-env/generate-ors-env/references/architecture.md +113 -0
- package/skills/rl-env/generate-verifiers-env/SKILL.md +188 -0
- package/skills/rl-env/generate-verifiers-env/references/architecture.md +119 -0
- package/skills/rl-env/rl-env-from-description/SKILL.md +124 -0
- package/skills/rl-env/rl-env-from-description/references/interview.md +75 -0
- package/skills/rl-env/rl-env-from-description/references/nemo_gym.md +41 -0
- package/skills/rl-env/rl-env-from-description/references/openenv.md +35 -0
- package/skills/rl-env/rl-env-from-description/references/ors.md +50 -0
- package/skills/rl-env/rl-env-from-description/references/verifiers.md +39 -0
- package/skills/tezgah-contract/EVALS.md +78 -0
- package/skills/tezgah-contract/SKILL.md +792 -0
- package/statusline.py +129 -0
- package/workflows/graph-impact.js +153 -0
- package/workflows/graph-map.js +158 -0
- package/workflows/graph-review.js +170 -0
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
"""Opt-in static embeddings beside BM25: which of a few short texts a query is about.
|
|
2
|
+
|
|
3
|
+
`tezgah_rank` matches words, so a Turkish question meets an English page only
|
|
4
|
+
through the phrasings `docs/index.json` carries, and a lesson worded differently
|
|
5
|
+
from the prompt is missed. A static embedding model (one vector per token,
|
|
6
|
+
mean-pooled - no network, no third-party package) ranks by meaning. The two
|
|
7
|
+
callers use it differently, each the way it measured best: the lessons block
|
|
8
|
+
keeps BM25's order and adds a line by meaning only above the model's cosine
|
|
9
|
+
`floor` (`fuse`), and the docs fallback ranks pages by meaning alone (`nearest`).
|
|
10
|
+
|
|
11
|
+
Off by default. `tezgah-setup --enable embed-mrl` (or `embed-m2v`) runs
|
|
12
|
+
`fetch()` once: the pinned source files over HTTPS, a stdlib conversion into one
|
|
13
|
+
compact file under the tezgah cache, and a sha256 check of both ends. At hook
|
|
14
|
+
time the file is read only when the feature is selected and the file is the
|
|
15
|
+
pinned one (`valid`); any other state, or any error, is BM25 exactly as
|
|
16
|
+
`tezgah_rank.rank` answers it. Nothing here downloads outside `fetch()`.
|
|
17
|
+
|
|
18
|
+
Measured (an internal research line, 200 real prompts over a 46-line
|
|
19
|
+
ledger, two blind raters): reciprocal-rank fusion gave every prompt three
|
|
20
|
+
lessons, 94% of them irrelevant. BM25 first plus the floor gives a no-topic
|
|
21
|
+
prompt a lesson 0.17 of the time (BM25 alone 0.10-0.14) at a recall@3 at most
|
|
22
|
+
0.02 above BM25's, for the price of loading the model on every prompt. On
|
|
23
|
+
held-out Turkish docs phrasings cosine alone found the page in the top 3 for 0.91
|
|
24
|
+
(embed-mrl) against the fusion's 0.75.
|
|
25
|
+
|
|
26
|
+
The file: MAGIC, a little-endian u64 header length, the header (JSON: the
|
|
27
|
+
tokenizer and the source pins), then `rows` records of a float32 scale followed
|
|
28
|
+
by `dim` int8 values. Rows are read with os.pread, only for the tokens a text
|
|
29
|
+
uses.
|
|
30
|
+
"""
|
|
31
|
+
import array
|
|
32
|
+
import hashlib
|
|
33
|
+
import json
|
|
34
|
+
import math
|
|
35
|
+
import os
|
|
36
|
+
import re
|
|
37
|
+
import shutil
|
|
38
|
+
import struct
|
|
39
|
+
import sys
|
|
40
|
+
import unicodedata
|
|
41
|
+
|
|
42
|
+
import tezgah_paths as tp
|
|
43
|
+
import tezgah_rank
|
|
44
|
+
|
|
45
|
+
MAGIC = b"TZEMB1\n\0"
|
|
46
|
+
URL = "https://huggingface.co/%s/resolve/%s/%s"
|
|
47
|
+
LITTLE = sys.byteorder == "little"
|
|
48
|
+
|
|
49
|
+
# Pinned by repository, commit and sha256 of every source file and of the file
|
|
50
|
+
# the conversion produces, so `fetch()` either writes exactly the measured table
|
|
51
|
+
# or nothing. The recipes are the research exports: V5-mrl keeps the first 128
|
|
52
|
+
# of 1024 Matryoshka dims; V5-m2v drops the vocabulary tail Tokenlearn appended
|
|
53
|
+
# and projects onto the top 128 uncentered principal axes. `floor` is the cosine
|
|
54
|
+
# a lesson BM25 missed must reach (`fuse`), chosen per model on half of the
|
|
55
|
+
# relevance-measurement prompts (the smallest that gave a lesson to at most 30% of
|
|
56
|
+
# the no-topic prompts) and quoted from the other half.
|
|
57
|
+
MODELS = {
|
|
58
|
+
"embed-mrl": {
|
|
59
|
+
"repo": "sentence-transformers/static-similarity-mrl-multilingual-v1",
|
|
60
|
+
"revision": "b68f4122911bcffcd6e1f695f2d99cd6788972d8",
|
|
61
|
+
"license": "Apache-2.0",
|
|
62
|
+
"files": {
|
|
63
|
+
"model": ("0_StaticEmbedding/model.safetensors",
|
|
64
|
+
"8245ab78ee71dded845a82d2270fcb9e785b29dad0e1619f69d5390c47d9ba00"),
|
|
65
|
+
"tokenizer": ("0_StaticEmbedding/tokenizer.json",
|
|
66
|
+
"11aaf894a4ccf3d95e8830e27c0f8152791fbbff2b988e29a265580b86edd216")},
|
|
67
|
+
"dims": 128, "dims_mode": "head", "vocab": "all", "floor": 0.30,
|
|
68
|
+
"sha256": "6f67d97229db9eda0dad4da677329f93ecd7ebc7b1b7195138cd215f676a19f2"},
|
|
69
|
+
"embed-m2v": {
|
|
70
|
+
"repo": "minishlab/potion-multilingual-128M",
|
|
71
|
+
"revision": "73908c3438cf03b6a01bcb9611d62b23d0726f08",
|
|
72
|
+
"license": "MIT",
|
|
73
|
+
"files": {
|
|
74
|
+
"model": ("model.safetensors",
|
|
75
|
+
"14b5eb39cb4ce5666da8ad1f3dc6be4346e9b2d601c073302fa0a31bf7943397"),
|
|
76
|
+
"tokenizer": ("tokenizer.json",
|
|
77
|
+
"19f1909063da3cfe3bd83a782381f040dccea475f4816de11116444a73e1b6a1")},
|
|
78
|
+
"dims": 128, "dims_mode": "pca", "vocab": "base", "floor": 0.50,
|
|
79
|
+
"sha256": "6673b36dae49ca42f15a82ea0724570807c9a6d80fa31cafa9fb89ee78d3fd09"},
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# --- the reader -------------------------------------------------------------
|
|
84
|
+
# Ported from the research reader (token ids identical to model2vec 0.9.0 on
|
|
85
|
+
# 244 texts, top-5 identical on 32 queries, same output under Python 3.10 -I -S).
|
|
86
|
+
|
|
87
|
+
def _is_punct(ch):
|
|
88
|
+
cp = ord(ch)
|
|
89
|
+
if 33 <= cp <= 47 or 58 <= cp <= 64 or 91 <= cp <= 96 or 123 <= cp <= 126:
|
|
90
|
+
return True
|
|
91
|
+
return unicodedata.category(ch).startswith("P")
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _is_cjk(cp):
|
|
95
|
+
return (0x4E00 <= cp <= 0x9FFF or 0x3400 <= cp <= 0x4DBF or 0x20000 <= cp <= 0x2A6DF
|
|
96
|
+
or 0x2A700 <= cp <= 0x2B73F or 0x2B740 <= cp <= 0x2B81F or 0x2B820 <= cp <= 0x2CEAF
|
|
97
|
+
or 0xF900 <= cp <= 0xFAFF or 0x2F800 <= cp <= 0x2FA1F)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class WordPiece:
|
|
101
|
+
"""BERT normalizer (clean, CJK, strip accents, lowercase) + BertPreTokenizer + WordPiece."""
|
|
102
|
+
|
|
103
|
+
def __init__(self, tokens, meta):
|
|
104
|
+
self.ids = {t: i for i, t in enumerate(tokens)}
|
|
105
|
+
self.unk = self.ids.get(meta.get("unk_token", "[UNK]"))
|
|
106
|
+
self.lower = meta.get("lowercase", True)
|
|
107
|
+
self.strip = meta.get("strip_accents")
|
|
108
|
+
if self.strip is None:
|
|
109
|
+
self.strip = self.lower
|
|
110
|
+
self.prefix = meta.get("prefix", "##")
|
|
111
|
+
self.max_chars = meta.get("max_input_chars_per_word", 100)
|
|
112
|
+
|
|
113
|
+
def normalize(self, text):
|
|
114
|
+
out = []
|
|
115
|
+
for ch in text:
|
|
116
|
+
cp = ord(ch)
|
|
117
|
+
if cp == 0 or cp == 0xFFFD:
|
|
118
|
+
continue
|
|
119
|
+
cat = unicodedata.category(ch)
|
|
120
|
+
if ch in "\t\n\r" or cat == "Zs" or ch.isspace():
|
|
121
|
+
out.append(" ")
|
|
122
|
+
continue
|
|
123
|
+
if cat in ("Cc", "Cf"):
|
|
124
|
+
continue
|
|
125
|
+
if _is_cjk(cp):
|
|
126
|
+
out.append(" " + ch + " ")
|
|
127
|
+
continue
|
|
128
|
+
out.append(ch)
|
|
129
|
+
text = "".join(out)
|
|
130
|
+
if self.strip:
|
|
131
|
+
text = "".join(c for c in unicodedata.normalize("NFD", text)
|
|
132
|
+
if unicodedata.category(c) != "Mn")
|
|
133
|
+
if self.lower:
|
|
134
|
+
text = text.lower()
|
|
135
|
+
return text
|
|
136
|
+
|
|
137
|
+
def words(self, text):
|
|
138
|
+
words, cur = [], []
|
|
139
|
+
for ch in text:
|
|
140
|
+
if ch.isspace():
|
|
141
|
+
if cur:
|
|
142
|
+
words.append("".join(cur))
|
|
143
|
+
cur = []
|
|
144
|
+
elif _is_punct(ch):
|
|
145
|
+
if cur:
|
|
146
|
+
words.append("".join(cur))
|
|
147
|
+
cur = []
|
|
148
|
+
words.append(ch)
|
|
149
|
+
else:
|
|
150
|
+
cur.append(ch)
|
|
151
|
+
if cur:
|
|
152
|
+
words.append("".join(cur))
|
|
153
|
+
return words
|
|
154
|
+
|
|
155
|
+
def encode(self, text):
|
|
156
|
+
ids = []
|
|
157
|
+
for word in self.words(self.normalize(text)):
|
|
158
|
+
if len(word) > self.max_chars:
|
|
159
|
+
ids.append(self.unk)
|
|
160
|
+
continue
|
|
161
|
+
start, pieces = 0, []
|
|
162
|
+
while start < len(word):
|
|
163
|
+
end, found = len(word), None
|
|
164
|
+
while start < end:
|
|
165
|
+
sub = word[start:end]
|
|
166
|
+
if start > 0:
|
|
167
|
+
sub = self.prefix + sub
|
|
168
|
+
if sub in self.ids:
|
|
169
|
+
found = self.ids[sub]
|
|
170
|
+
break
|
|
171
|
+
end -= 1
|
|
172
|
+
if found is None:
|
|
173
|
+
pieces = [self.unk]
|
|
174
|
+
break
|
|
175
|
+
pieces.append(found)
|
|
176
|
+
start = end
|
|
177
|
+
ids.extend(pieces)
|
|
178
|
+
return ids
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class Unigram:
|
|
182
|
+
"""SentencePiece-style Unigram (XLM-R): NFKC (stands in for the precompiled
|
|
183
|
+
charsmap), the export's string replacements, Metaspace, Viterbi."""
|
|
184
|
+
|
|
185
|
+
def __init__(self, pieces, scores, meta):
|
|
186
|
+
self.ids = {p: i for i, p in enumerate(pieces)}
|
|
187
|
+
self.scores = scores
|
|
188
|
+
self.unk = meta.get("unk_id", 1)
|
|
189
|
+
for special in meta.get("skip_pieces", []):
|
|
190
|
+
self.ids.pop(special, None)
|
|
191
|
+
self.maxlen = max(len(p) for p in self.ids)
|
|
192
|
+
self.unk_score = min(scores) - 10.0
|
|
193
|
+
self.ops = [(op[0], re.compile(op[1]), op[2]) if op[0] == "re" else tuple(op)
|
|
194
|
+
for op in meta.get("replacements", [])]
|
|
195
|
+
|
|
196
|
+
def normalize(self, text):
|
|
197
|
+
for op in self.ops:
|
|
198
|
+
if op[0] == "nfkc":
|
|
199
|
+
text = unicodedata.normalize("NFKC", text)
|
|
200
|
+
elif op[0] == "str":
|
|
201
|
+
text = text.replace(op[1], op[2])
|
|
202
|
+
elif op[0] == "re":
|
|
203
|
+
text = op[1].sub(op[2], text)
|
|
204
|
+
elif op[0] == "strip":
|
|
205
|
+
text = text.lstrip() if op[1] else text
|
|
206
|
+
text = text.rstrip() if op[2] else text
|
|
207
|
+
text = text.replace(" ", "\u2581")
|
|
208
|
+
if not text.startswith("\u2581"):
|
|
209
|
+
text = "\u2581" + text
|
|
210
|
+
return text
|
|
211
|
+
|
|
212
|
+
def encode(self, text):
|
|
213
|
+
s = self.normalize(text)
|
|
214
|
+
n = len(s)
|
|
215
|
+
best = [None] * (n + 1)
|
|
216
|
+
back = [None] * (n + 1)
|
|
217
|
+
best[0] = 0.0
|
|
218
|
+
ids, scores, maxlen = self.ids, self.scores, self.maxlen
|
|
219
|
+
for pos in range(n):
|
|
220
|
+
base = best[pos]
|
|
221
|
+
if base is None:
|
|
222
|
+
continue
|
|
223
|
+
single = False
|
|
224
|
+
for length in range(1, min(maxlen, n - pos) + 1):
|
|
225
|
+
pid = ids.get(s[pos:pos + length])
|
|
226
|
+
if pid is None:
|
|
227
|
+
continue
|
|
228
|
+
if length == 1:
|
|
229
|
+
single = True
|
|
230
|
+
cand = base + scores[pid]
|
|
231
|
+
end = pos + length
|
|
232
|
+
if best[end] is None or cand > best[end]:
|
|
233
|
+
best[end] = cand
|
|
234
|
+
back[end] = (pos, pid)
|
|
235
|
+
if not single:
|
|
236
|
+
cand = base + self.unk_score
|
|
237
|
+
if best[pos + 1] is None or cand > best[pos + 1]:
|
|
238
|
+
best[pos + 1] = cand
|
|
239
|
+
back[pos + 1] = (pos, self.unk)
|
|
240
|
+
out, end = [], n
|
|
241
|
+
while end > 0:
|
|
242
|
+
pos, pid = back[end]
|
|
243
|
+
out.append(pid)
|
|
244
|
+
end = pos
|
|
245
|
+
out.reverse()
|
|
246
|
+
return out
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
class Reader:
|
|
250
|
+
"""One model file: tokenize, look up int8 rows, mean-pool, normalise."""
|
|
251
|
+
|
|
252
|
+
def __init__(self, path):
|
|
253
|
+
with open(path, "rb") as fh:
|
|
254
|
+
if fh.read(len(MAGIC)) != MAGIC:
|
|
255
|
+
raise ValueError("%s: not a tezgah embedding file" % path)
|
|
256
|
+
size = struct.unpack("<Q", fh.read(8))[0]
|
|
257
|
+
meta = json.loads(fh.read(size).decode("utf-8"))
|
|
258
|
+
self.base = len(MAGIC) + 8 + size
|
|
259
|
+
self.dim = meta["dim"]
|
|
260
|
+
self.row_bytes = 4 + self.dim
|
|
261
|
+
if os.path.getsize(path) != self.base + meta["rows"] * self.row_bytes:
|
|
262
|
+
raise ValueError("%s: size does not match its header" % path)
|
|
263
|
+
if meta["tokenizer"] == "wordpiece":
|
|
264
|
+
self.tok = WordPiece(meta["vocab"], meta)
|
|
265
|
+
else:
|
|
266
|
+
self.tok = Unigram([p for p, _s in meta["pieces"]],
|
|
267
|
+
[s for _p, s in meta["pieces"]], meta)
|
|
268
|
+
self.unk = meta.get("unk_id")
|
|
269
|
+
self.fd = os.open(path, os.O_RDONLY)
|
|
270
|
+
self.cache = {}
|
|
271
|
+
|
|
272
|
+
def row(self, i):
|
|
273
|
+
vec = self.cache.get(i)
|
|
274
|
+
if vec is None:
|
|
275
|
+
raw = os.pread(self.fd, self.row_bytes, self.base + i * self.row_bytes)
|
|
276
|
+
scale = struct.unpack("<f", raw[:4])[0]
|
|
277
|
+
vec = self.cache[i] = [x * scale for x in array.array("b", raw[4:])]
|
|
278
|
+
return vec
|
|
279
|
+
|
|
280
|
+
def tokenize(self, text):
|
|
281
|
+
return [i for i in self.tok.encode(text) if i != self.unk]
|
|
282
|
+
|
|
283
|
+
def embed(self, text):
|
|
284
|
+
acc = [0.0] * self.dim
|
|
285
|
+
for i in self.tokenize(text):
|
|
286
|
+
for k, v in enumerate(self.row(i)):
|
|
287
|
+
acc[k] += v
|
|
288
|
+
norm = math.sqrt(sum(v * v for v in acc))
|
|
289
|
+
return [v / norm for v in acc] if norm else acc
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def cosine(a, b):
|
|
293
|
+
return sum(x * y for x, y in zip(a, b))
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
# --- the hook-time half -----------------------------------------------------
|
|
297
|
+
|
|
298
|
+
def model_path(ident):
|
|
299
|
+
return os.path.join(tp.CACHE, "embed", ident + ".bin")
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _sha256(path):
|
|
303
|
+
h = hashlib.sha256()
|
|
304
|
+
with open(path, "rb") as fh:
|
|
305
|
+
for block in iter(lambda: fh.read(1 << 20), b""):
|
|
306
|
+
h.update(block)
|
|
307
|
+
return h.hexdigest()
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def valid(ident):
|
|
311
|
+
"""The model file's path when it is the pinned one, else None. A pure read:
|
|
312
|
+
the `--features` probe and every hook-time load ask this."""
|
|
313
|
+
path = model_path(ident)
|
|
314
|
+
try:
|
|
315
|
+
return path if _sha256(path) == MODELS[ident]["sha256"] else None
|
|
316
|
+
except (OSError, KeyError):
|
|
317
|
+
return None
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
_LOADED = {}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def reader():
|
|
324
|
+
"""The selected model's Reader, carrying its `floor`, or None: not selected,
|
|
325
|
+
not fetched, not the pinned file, or anything at all that raised."""
|
|
326
|
+
try:
|
|
327
|
+
import tezgah_apps
|
|
328
|
+
for ident in tezgah_apps.selected_ids(tp.config().get("features")):
|
|
329
|
+
path = valid(ident) if ident in MODELS else None
|
|
330
|
+
if path:
|
|
331
|
+
if path not in _LOADED:
|
|
332
|
+
_LOADED[path] = Reader(path)
|
|
333
|
+
_LOADED[path].floor = MODELS[ident].get("floor")
|
|
334
|
+
return _LOADED[path]
|
|
335
|
+
except Exception: # fail-open: the caller ranks by words alone
|
|
336
|
+
return None
|
|
337
|
+
return None
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def _cosines(model, query, texts, groups):
|
|
341
|
+
"""Each text's best cosine to `query` over its `groups` strings (default:
|
|
342
|
+
the text itself), or None when the query has no token the model knows."""
|
|
343
|
+
q = model.embed(query)
|
|
344
|
+
if not any(q):
|
|
345
|
+
return None
|
|
346
|
+
return [max((cosine(q, model.embed(t)) for t in g), default=-1.0)
|
|
347
|
+
for g in (groups or [[t] for t in texts])]
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def fuse(query, texts, k, groups=None, max_df=None):
|
|
351
|
+
"""Indices of the `k` texts most about `query`, best first: the lessons ranking.
|
|
352
|
+
|
|
353
|
+
BM25's own order first - with no usable model this is exactly
|
|
354
|
+
`tezgah_rank.rank(query, texts, k, max_df)`, `max_df` being the lessons
|
|
355
|
+
path's cap - then the texts BM25 missed, by cosine, each only when it reaches
|
|
356
|
+
the model's `floor` (a model with none fills unconditionally), so a prompt
|
|
357
|
+
about nothing gets nothing."""
|
|
358
|
+
words = tezgah_rank.rank(query, texts, len(texts), max_df)
|
|
359
|
+
model = reader()
|
|
360
|
+
if model is None:
|
|
361
|
+
return words[:k]
|
|
362
|
+
try:
|
|
363
|
+
sims = _cosines(model, query, texts, groups)
|
|
364
|
+
if sims is None:
|
|
365
|
+
return words[:k]
|
|
366
|
+
hits, floor = set(words), model.floor
|
|
367
|
+
more = sorted((i for i in range(len(texts)) if i not in hits
|
|
368
|
+
and (floor is None or sims[i] >= floor)),
|
|
369
|
+
key=lambda i: (-sims[i], i))
|
|
370
|
+
return (words + more)[:k]
|
|
371
|
+
except Exception: # fail-open
|
|
372
|
+
return words[:k]
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def nearest(query, texts, k, groups=None):
|
|
376
|
+
"""Indices of the `k` texts nearest `query` by cosine alone, best first: the
|
|
377
|
+
docs ranking, where BM25's matches on Turkish function words outvoted the
|
|
378
|
+
meaning. With no usable model, `tezgah_rank.rank(query, texts, k)` exactly."""
|
|
379
|
+
model = reader()
|
|
380
|
+
if model is not None:
|
|
381
|
+
try:
|
|
382
|
+
sims = _cosines(model, query, texts, groups)
|
|
383
|
+
if sims is not None:
|
|
384
|
+
return sorted(range(len(texts)), key=lambda i: (-sims[i], i))[:k]
|
|
385
|
+
except Exception: # fail-open
|
|
386
|
+
pass
|
|
387
|
+
return tezgah_rank.rank(query, texts, k)
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
# --- the setup-time half: fetch, convert, verify ----------------------------
|
|
391
|
+
# Runs from `tezgah-setup --enable`, never from a hook. Every value is
|
|
392
|
+
# reproducible bit for bit on any Python >= 3.10: the int8 rounding emulates the
|
|
393
|
+
# float32 arithmetic of the research export, and the PCA is exact integer
|
|
394
|
+
# arithmetic (Gram matrix, projection) around a cyclic Jacobi eigensolver that
|
|
395
|
+
# uses only + - * / and sqrt.
|
|
396
|
+
|
|
397
|
+
class _Progress:
|
|
398
|
+
"""One status line for a long setup step: rewritten in place on a terminal,
|
|
399
|
+
one line per 10% otherwise (a log keeps a readable trail, not 400 updates)."""
|
|
400
|
+
|
|
401
|
+
def __init__(self, label, total, unit="", scale=1):
|
|
402
|
+
self.label, self.total, self.unit, self.scale = label, total, unit, scale
|
|
403
|
+
self.done, self.step = 0, -1
|
|
404
|
+
self.tty = sys.stdout.isatty()
|
|
405
|
+
|
|
406
|
+
def __call__(self, n=1):
|
|
407
|
+
self.done += n
|
|
408
|
+
shown = "%d" % (self.done // self.scale)
|
|
409
|
+
if self.total:
|
|
410
|
+
pct = min(100, self.done * 100 // self.total)
|
|
411
|
+
shown += "/%d%s %d%%" % (self.total // self.scale, self.unit, pct)
|
|
412
|
+
if not self.tty and pct // 10 == self.step:
|
|
413
|
+
return
|
|
414
|
+
self.step = pct // 10
|
|
415
|
+
else:
|
|
416
|
+
shown += self.unit
|
|
417
|
+
if not self.tty:
|
|
418
|
+
return
|
|
419
|
+
sys.stdout.write(("\r %s %s" if self.tty else " %s %s\n") % (self.label, shown))
|
|
420
|
+
sys.stdout.flush()
|
|
421
|
+
|
|
422
|
+
def close(self):
|
|
423
|
+
if self.tty:
|
|
424
|
+
sys.stdout.write("\n")
|
|
425
|
+
sys.stdout.flush()
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
def _download(url, dest):
|
|
429
|
+
"""Stream `url` into `dest`; returns the sha256 of what was written."""
|
|
430
|
+
import urllib.request
|
|
431
|
+
h = hashlib.sha256()
|
|
432
|
+
with urllib.request.urlopen(url, timeout=60) as resp, open(dest, "wb") as out:
|
|
433
|
+
total = int(resp.headers.get("Content-Length") or 0)
|
|
434
|
+
tick = _Progress("downloaded", total, " MB", 1 << 20)
|
|
435
|
+
for block in iter(lambda: resp.read(1 << 20), b""):
|
|
436
|
+
h.update(block)
|
|
437
|
+
out.write(block)
|
|
438
|
+
tick(len(block))
|
|
439
|
+
tick.close()
|
|
440
|
+
return h.hexdigest()
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def _tensor(path):
|
|
444
|
+
"""(data offset, rows, cols) of the one float32 embedding table in a
|
|
445
|
+
safetensors file."""
|
|
446
|
+
with open(path, "rb") as fh:
|
|
447
|
+
size = struct.unpack("<Q", fh.read(8))[0]
|
|
448
|
+
header = json.loads(fh.read(size).decode("utf-8"))
|
|
449
|
+
name = "embeddings" if "embeddings" in header else "embedding.weight"
|
|
450
|
+
t = header[name]
|
|
451
|
+
if t["dtype"] != "F32" or len(t["shape"]) != 2:
|
|
452
|
+
raise ValueError("%s: %s is %s %s, not a float32 matrix"
|
|
453
|
+
% (path, name, t["dtype"], t["shape"]))
|
|
454
|
+
return 8 + size + t["data_offsets"][0], t["shape"][0], t["shape"][1]
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def _rows(job):
|
|
458
|
+
"""The float32 rows [start, stop) of the table in job as arrays."""
|
|
459
|
+
path, base, cols, start, stop = job[:5]
|
|
460
|
+
stride = 4 * cols
|
|
461
|
+
fd = os.open(path, os.O_RDONLY)
|
|
462
|
+
try:
|
|
463
|
+
raw = os.pread(fd, (stop - start) * stride, base + start * stride)
|
|
464
|
+
finally:
|
|
465
|
+
os.close(fd)
|
|
466
|
+
for r in range(stop - start):
|
|
467
|
+
a = array.array("f", raw[r * stride:(r + 1) * stride])
|
|
468
|
+
if not LITTLE:
|
|
469
|
+
a.byteswap()
|
|
470
|
+
yield a
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def _quantise(values):
|
|
474
|
+
"""One row as a float32 scale + int8 values, rounded exactly as numpy does
|
|
475
|
+
it in float32: scale = max|x| / 127, q = clip(rint(x / scale), -127, 127)."""
|
|
476
|
+
v = array.array("f", values)
|
|
477
|
+
scale = array.array("f", [max(map(abs, v), default=0.0) / 127.0])[0] or 1.0
|
|
478
|
+
q = array.array("f", [x / scale for x in v])
|
|
479
|
+
return struct.pack("<f", scale) + array.array(
|
|
480
|
+
"b", [max(-127, min(127, round(x))) for x in q]).tobytes()
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
# Signed integers packed 64 bits apart into one Python int, so one big-int
|
|
484
|
+
# multiply-add does a whole row of fixed-point products in C.
|
|
485
|
+
_B62, _B63 = 1 << 62, 1 << 63
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def _offset(n, bias):
|
|
489
|
+
return sum(bias << (64 * j) for j in range(n))
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
def _pack(ints):
|
|
493
|
+
n = len(ints)
|
|
494
|
+
return (int.from_bytes(struct.pack("<%dQ" % n, *[v + _B62 for v in ints]), "little")
|
|
495
|
+
- _offset(n, _B62))
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def _unpack(big, n):
|
|
499
|
+
raw = (big + _offset(n, _B63)).to_bytes(8 * n, "little")
|
|
500
|
+
return [f - _B63 for f in struct.unpack("<%dQ" % n, raw)]
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
def _absmax_part(job):
|
|
504
|
+
return max((max(map(abs, row)) for row in _rows(job)), default=0.0)
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def _gram_part(job):
|
|
508
|
+
"""sum(row^T row) over the job's rows, the row scaled by 2**shift to
|
|
509
|
+
integers below 2**20: each of the cols accumulators packs one Gram row."""
|
|
510
|
+
shift = job[5]
|
|
511
|
+
acc = [0] * job[2]
|
|
512
|
+
for row in _rows(job):
|
|
513
|
+
ints = [round(math.ldexp(x, shift)) for x in row]
|
|
514
|
+
packed = _pack(ints)
|
|
515
|
+
for i, v in enumerate(ints):
|
|
516
|
+
if v:
|
|
517
|
+
acc[i] += v * packed
|
|
518
|
+
return acc
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def _head_part(job):
|
|
522
|
+
dims = job[5]
|
|
523
|
+
return b"".join(_quantise(row[:dims]) for row in _rows(job))
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
def _pca_part(job):
|
|
527
|
+
"""Each row projected onto the packed axes (fixed point: the row below
|
|
528
|
+
2**20, the axes at 2**30), then quantised."""
|
|
529
|
+
axes, dims = job[5], job[6]
|
|
530
|
+
out = []
|
|
531
|
+
for row in _rows(job):
|
|
532
|
+
top = max(map(abs, row), default=0.0)
|
|
533
|
+
if not top:
|
|
534
|
+
out.append(_quantise([0.0] * dims))
|
|
535
|
+
continue
|
|
536
|
+
shift = 20 - math.frexp(top)[1]
|
|
537
|
+
acc = 0
|
|
538
|
+
for x, w in zip(row, axes):
|
|
539
|
+
if x:
|
|
540
|
+
acc += round(math.ldexp(x, shift)) * w
|
|
541
|
+
out.append(_quantise([math.ldexp(v, -(shift + 30)) for v in _unpack(acc, dims)]))
|
|
542
|
+
return b"".join(out)
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
def _map(fn, jobs, label=""):
|
|
546
|
+
"""fn over jobs in order, on every core when there is more than one job;
|
|
547
|
+
the integer partial sums make the result independent of the split. A
|
|
548
|
+
`label` prints a chunk counter while it runs."""
|
|
549
|
+
tick = _Progress(label, len(jobs), " chunks") if label else (lambda n=1: None)
|
|
550
|
+
if len(jobs) < 2:
|
|
551
|
+
out = []
|
|
552
|
+
for j in jobs:
|
|
553
|
+
out.append(fn(j))
|
|
554
|
+
tick()
|
|
555
|
+
else:
|
|
556
|
+
import concurrent.futures
|
|
557
|
+
with concurrent.futures.ProcessPoolExecutor(max_workers=os.cpu_count() or 1) as pool:
|
|
558
|
+
out = []
|
|
559
|
+
for part in pool.map(fn, jobs):
|
|
560
|
+
out.append(part)
|
|
561
|
+
tick()
|
|
562
|
+
if label:
|
|
563
|
+
tick.close()
|
|
564
|
+
return out
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def _jacobi(a):
|
|
568
|
+
"""(eigenvalues, eigenvectors as lists) of the symmetric matrix `a` (list of
|
|
569
|
+
rows, modified in place): cyclic Jacobi rotations (Numerical Recipes'
|
|
570
|
+
`jacobi`), deterministic because it uses only + - * / and sqrt."""
|
|
571
|
+
n = len(a)
|
|
572
|
+
vt = [[1.0 if i == j else 0.0 for j in range(n)] for i in range(n)]
|
|
573
|
+
for sweep in range(100):
|
|
574
|
+
if not any(a[p][q] for p in range(n) for q in range(p + 1, n)):
|
|
575
|
+
break
|
|
576
|
+
for p in range(n - 1):
|
|
577
|
+
for q in range(p + 1, n):
|
|
578
|
+
apq = a[p][q]
|
|
579
|
+
if not apq:
|
|
580
|
+
continue
|
|
581
|
+
g = 100.0 * abs(apq)
|
|
582
|
+
if sweep > 3 and abs(a[p][p]) + g == abs(a[p][p]) \
|
|
583
|
+
and abs(a[q][q]) + g == abs(a[q][q]):
|
|
584
|
+
a[p][q] = a[q][p] = 0.0
|
|
585
|
+
continue
|
|
586
|
+
theta = (a[q][q] - a[p][p]) / (2.0 * apq)
|
|
587
|
+
t = 1.0 / (abs(theta) + math.sqrt(theta * theta + 1.0))
|
|
588
|
+
if theta < 0:
|
|
589
|
+
t = -t
|
|
590
|
+
c = 1.0 / math.sqrt(t * t + 1.0)
|
|
591
|
+
s = t * c
|
|
592
|
+
rp, rq = a[p], a[q]
|
|
593
|
+
newp = [c * x - s * y for x, y in zip(rp, rq)]
|
|
594
|
+
newq = [s * x + c * y for x, y in zip(rp, rq)]
|
|
595
|
+
newp[p], newq[q] = rp[p] - t * apq, rq[q] + t * apq
|
|
596
|
+
newp[q] = newq[p] = 0.0
|
|
597
|
+
a[p], a[q] = newp, newq
|
|
598
|
+
for j in range(n):
|
|
599
|
+
a[j][p], a[j][q] = newp[j], newq[j]
|
|
600
|
+
vp, vq = vt[p], vt[q]
|
|
601
|
+
vt[p] = [c * x - s * y for x, y in zip(vp, vq)]
|
|
602
|
+
vt[q] = [s * x + c * y for x, y in zip(vp, vq)]
|
|
603
|
+
return [a[i][i] for i in range(n)], vt
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
def _tokenizer(path, vocab):
|
|
607
|
+
"""(header fields, rows kept) from a tokenizer.json, as the research export."""
|
|
608
|
+
with open(path, encoding="utf-8") as fh:
|
|
609
|
+
tok = json.load(fh)
|
|
610
|
+
model = tok["model"]
|
|
611
|
+
if model["type"] == "WordPiece":
|
|
612
|
+
norm = tok["normalizer"]
|
|
613
|
+
tokens = [None] * len(model["vocab"])
|
|
614
|
+
for t, i in model["vocab"].items():
|
|
615
|
+
tokens[i] = t
|
|
616
|
+
return {"tokenizer": "wordpiece", "unk_token": model["unk_token"],
|
|
617
|
+
"unk_id": model["vocab"][model["unk_token"]],
|
|
618
|
+
"prefix": model["continuing_subword_prefix"],
|
|
619
|
+
"max_input_chars_per_word": model["max_input_chars_per_word"],
|
|
620
|
+
"lowercase": norm.get("lowercase", True),
|
|
621
|
+
"strip_accents": norm.get("strip_accents"), "vocab": tokens}, len(tokens)
|
|
622
|
+
pieces = model["vocab"]
|
|
623
|
+
keep = len(pieces)
|
|
624
|
+
if vocab == "base":
|
|
625
|
+
# drop the trailing run of pieces that share the minimum score
|
|
626
|
+
while keep > 0 and pieces[keep - 1][1] == pieces[-1][1]:
|
|
627
|
+
keep -= 1
|
|
628
|
+
ops = []
|
|
629
|
+
|
|
630
|
+
def walk(n):
|
|
631
|
+
"""The normalizer as ordered ops; Precompiled (the SentencePiece charsmap)
|
|
632
|
+
is stood in for by NFKC in the reader."""
|
|
633
|
+
kind = n["type"]
|
|
634
|
+
if kind == "Sequence":
|
|
635
|
+
for c in n["normalizers"]:
|
|
636
|
+
walk(c)
|
|
637
|
+
elif kind == "Precompiled":
|
|
638
|
+
ops.append(["nfkc"])
|
|
639
|
+
elif kind == "Replace" and "String" in n["pattern"]:
|
|
640
|
+
ops.append(["str", n["pattern"]["String"], n["content"]])
|
|
641
|
+
elif kind == "Replace" and "Regex" in n["pattern"]:
|
|
642
|
+
ops.append(["re", n["pattern"]["Regex"], n["content"]])
|
|
643
|
+
elif kind == "Strip":
|
|
644
|
+
ops.append(["strip", n.get("strip_left", True), n.get("strip_right", True)])
|
|
645
|
+
else:
|
|
646
|
+
raise ValueError("normalizer %s not supported by the stdlib reader" % kind)
|
|
647
|
+
walk(tok["normalizer"])
|
|
648
|
+
return {"tokenizer": "unigram", "unk_id": model["unk_id"], "replacements": ops,
|
|
649
|
+
"skip_pieces": ["[PAD]", "[UNK]"],
|
|
650
|
+
"pieces": [list(p) for p in pieces[:keep]]}, keep
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
CHUNK = 8192
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
def convert(spec, model_file, tokenizer_file, out):
|
|
657
|
+
"""Write the compact model file for `spec` from its two source files."""
|
|
658
|
+
meta, rows = _tokenizer(tokenizer_file, spec["vocab"])
|
|
659
|
+
base, total, cols = _tensor(model_file)
|
|
660
|
+
if rows > total or spec["dims"] > cols:
|
|
661
|
+
raise ValueError("the tokenizer and the table do not fit together")
|
|
662
|
+
spans = [(model_file, base, cols, s, min(s + CHUNK, rows))
|
|
663
|
+
for s in range(0, rows, CHUNK)]
|
|
664
|
+
dims = spec["dims"]
|
|
665
|
+
if spec["dims_mode"] == "head":
|
|
666
|
+
body = _map(_head_part, [j + (dims,) for j in spans], "quantised")
|
|
667
|
+
else:
|
|
668
|
+
top = max(_map(_absmax_part, spans, "scanned 1/3"), default=0.0)
|
|
669
|
+
shift = 20 - math.frexp(top)[1] if top else 0
|
|
670
|
+
if rows >= 1 << 23: # 2**40 per product: the 64-bit field must hold the sum
|
|
671
|
+
raise ValueError("too many rows for the fixed-point Gram matrix")
|
|
672
|
+
gram = [sum(col) for col in zip(*_map(_gram_part, [j + (shift,) for j in spans],
|
|
673
|
+
"gram 2/3"))]
|
|
674
|
+
print(" solving %dx%d eigenproblem" % (cols, cols), flush=True)
|
|
675
|
+
values, vt = _jacobi([[float(v) for v in _unpack(g, cols)] for g in gram])
|
|
676
|
+
order = sorted(range(cols), key=lambda i: (-values[i], i))[:dims]
|
|
677
|
+
axes = [_pack([round(math.ldexp(vt[k][d], 30)) for k in order]) for d in range(cols)]
|
|
678
|
+
body = _map(_pca_part, [j + (axes, dims) for j in spans], "projected 3/3")
|
|
679
|
+
meta.update({"repo": spec["repo"], "revision": spec["revision"],
|
|
680
|
+
"sources": {r: f[1] for r, f in sorted(spec["files"].items())},
|
|
681
|
+
"dims_mode": spec["dims_mode"], "dim": dims, "rows": rows,
|
|
682
|
+
"dtype": "int8"})
|
|
683
|
+
header = json.dumps(meta, ensure_ascii=False, sort_keys=True,
|
|
684
|
+
separators=(",", ":")).encode("utf-8")
|
|
685
|
+
with open(out, "wb") as fh:
|
|
686
|
+
fh.write(MAGIC + struct.pack("<Q", len(header)) + header)
|
|
687
|
+
for part in body:
|
|
688
|
+
fh.write(part)
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
def _sweep(directory):
|
|
692
|
+
"""Delete the `.fetch-*` work dirs in `directory`: a fetch killed by SIGKILL
|
|
693
|
+
(the installer's timeout, Ctrl-C) skips its `finally` and leaves a partial
|
|
694
|
+
download of ~0.5 GB. Only real directories with that prefix; a symlink is
|
|
695
|
+
never followed."""
|
|
696
|
+
try:
|
|
697
|
+
names = os.listdir(directory)
|
|
698
|
+
except OSError:
|
|
699
|
+
return
|
|
700
|
+
for name in names:
|
|
701
|
+
path = os.path.join(directory, name)
|
|
702
|
+
if name.startswith(".fetch-") and os.path.isdir(path) and not os.path.islink(path):
|
|
703
|
+
shutil.rmtree(path, ignore_errors=True)
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
def fetch(ident, get=None):
|
|
707
|
+
"""Download, verify, convert and install the model for `ident`; returns its
|
|
708
|
+
path. Raises on any mismatch, leaving no model file and no temp file."""
|
|
709
|
+
import tempfile
|
|
710
|
+
spec = MODELS[ident]
|
|
711
|
+
get = get or _download
|
|
712
|
+
final = model_path(ident)
|
|
713
|
+
os.makedirs(os.path.dirname(final), mode=0o700, exist_ok=True)
|
|
714
|
+
# ponytail: assumes one fetch at a time; a second concurrent fetch would
|
|
715
|
+
# sweep the first one's work dir and fail it
|
|
716
|
+
_sweep(os.path.dirname(final))
|
|
717
|
+
work = tempfile.mkdtemp(prefix=".fetch-", dir=os.path.dirname(final))
|
|
718
|
+
try:
|
|
719
|
+
files = {}
|
|
720
|
+
for role, (rel, sha) in sorted(spec["files"].items()):
|
|
721
|
+
print(" fetching %s@%s %s" % (spec["repo"], spec["revision"][:12], rel),
|
|
722
|
+
flush=True)
|
|
723
|
+
files[role] = os.path.join(work, role)
|
|
724
|
+
got = get(URL % (spec["repo"], spec["revision"], rel), files[role])
|
|
725
|
+
if got != sha:
|
|
726
|
+
raise ValueError("%s: sha256 %s, pinned %s" % (rel, got, sha))
|
|
727
|
+
print(" converting (%s, %d dims, int8)" % (spec["dims_mode"], spec["dims"]),
|
|
728
|
+
flush=True)
|
|
729
|
+
tmp = os.path.join(work, "model.bin")
|
|
730
|
+
convert(spec, files["model"], files["tokenizer"], tmp)
|
|
731
|
+
got = _sha256(tmp)
|
|
732
|
+
if got != spec["sha256"]:
|
|
733
|
+
raise ValueError("converted file sha256 %s, pinned %s" % (got, spec["sha256"]))
|
|
734
|
+
os.chmod(tmp, 0o600)
|
|
735
|
+
os.replace(tmp, final)
|
|
736
|
+
finally:
|
|
737
|
+
shutil.rmtree(work, ignore_errors=True)
|
|
738
|
+
return final
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
def remove(ident):
|
|
742
|
+
"""Delete the model file for `ident` and any leftover fetch work dir; True
|
|
743
|
+
when there was a model file."""
|
|
744
|
+
_sweep(os.path.dirname(model_path(ident)))
|
|
745
|
+
try:
|
|
746
|
+
os.remove(model_path(ident))
|
|
747
|
+
return True
|
|
748
|
+
except OSError:
|
|
749
|
+
return False
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
def main(argv):
|
|
753
|
+
if len(argv) != 2 or argv[0] != "fetch" or argv[1] not in MODELS:
|
|
754
|
+
sys.stderr.write("usage: tezgah_embed.py fetch {%s}\n" % ",".join(MODELS))
|
|
755
|
+
return 2
|
|
756
|
+
try:
|
|
757
|
+
print(" %s -> %s" % (argv[1], fetch(argv[1])))
|
|
758
|
+
except Exception as exc: # one line for the installer's log
|
|
759
|
+
sys.stderr.write("tezgah_embed: %s: %s\n" % (argv[1], exc))
|
|
760
|
+
return 1
|
|
761
|
+
return 0
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
if __name__ == "__main__":
|
|
765
|
+
sys.exit(main(sys.argv[1:]))
|