tribunal-kit 9.2.3 → 9.2.4
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/.agent/.tribunal/session.jsonl +15 -0
- package/.agent/ARCHITECTURE.md +4 -4
- package/.agent/agents/agent-shield-auditor.md +18 -0
- package/.agent/agents/harness-manager.md +49 -0
- package/.agent/agents/human-gate-negotiator.md +22 -0
- package/.agent/agents/kernel-scheduler.md +56 -0
- package/.agent/agents/memory-archivist.md +37 -0
- package/.agent/agents/orchestrator.md +5 -0
- package/.agent/agents/project-planner.md +5 -0
- package/.agent/agents/security-auditor.md +5 -0
- package/.agent/rules/GEMINI.md +1 -1
- package/.agent/scripts/_utils.js +1 -1
- package/.agent/scripts/checklist.js +1 -1
- package/.agent/scripts/context_compiler.js +1 -1
- package/.agent/scripts/guardrail_engine.js +1 -1
- package/.agent/scripts/harness_manager.js +60 -0
- package/.agent/scripts/lint_runner.js +1 -1
- package/.agent/scripts/mcp_server.js +181 -0
- package/.agent/scripts/memory_archivist.js +97 -0
- package/.agent/scripts/memory_consolidator.js +37 -0
- package/.agent/scripts/memory_engine.js +61 -21
- package/.agent/scripts/pipeline_engine.js +17 -2
- package/.agent/scripts/session_logger.js +115 -0
- package/.agent/scripts/session_manager.js +10 -0
- package/.agent/scripts/swarm_dispatcher.js +74 -1
- package/.agent/scripts/syscall_registry.js +105 -0
- package/.agent/scripts/test_runner.js +1 -1
- package/.agent/scripts/verify_all.js +2 -2
- package/.agent/skill_topic_map.json +28 -1
- package/.agent/skills/agent-syscall-guidelines/SKILL.md +25 -0
- package/.agent/skills/agentic-workflows-2026/SKILL.md +8 -0
- package/.agent/skills/agentshield-security/SKILL.md +26 -0
- package/.agent/skills/context-engineering-pro/SKILL.md +7 -0
- package/.agent/skills/fabel-protocol/SKILL.md +5 -0
- package/.agent/skills/graph-engineering/SKILL.md +28 -0
- package/.agent/skills/harness-protocol/SKILL.md +8 -0
- package/.agent/skills/hf-cli/SKILL.md +239 -0
- package/.agent/skills/hf-cloud-aws-context-discovery/SKILL.md +74 -0
- package/.agent/skills/hf-cloud-python-env-setup/SKILL.md +90 -0
- package/.agent/skills/hf-cloud-python-env-setup/requirements.txt +17 -0
- package/.agent/skills/hf-cloud-python-env-setup/scripts/check_versions.py +29 -0
- package/.agent/skills/hf-cloud-python-env-setup/scripts/setup_env.py +143 -0
- package/.agent/skills/hf-cloud-sagemaker-deployment-planner/SKILL.md +90 -0
- package/.agent/skills/hf-cloud-sagemaker-iam-preflight/SKILL.md +102 -0
- package/.agent/skills/hf-cloud-sagemaker-iam-preflight/references/minimum-permissions.json +47 -0
- package/.agent/skills/hf-cloud-sagemaker-iam-preflight/references/trust-policy.json +12 -0
- package/.agent/skills/hf-cloud-sagemaker-iam-preflight/scripts/check_role.py +184 -0
- package/.agent/skills/hf-cloud-sagemaker-iam-preflight/scripts/create_role.py +118 -0
- package/.agent/skills/hf-cloud-sagemaker-production-defaults/SKILL.md +419 -0
- package/.agent/skills/hf-cloud-sagemaker-production-defaults/references/deployment-template.md +59 -0
- package/.agent/skills/hf-cloud-sagemaker-production-defaults/scripts/_common.py +148 -0
- package/.agent/skills/hf-cloud-sagemaker-production-defaults/scripts/deploy.py +327 -0
- package/.agent/skills/hf-cloud-sagemaker-production-defaults/scripts/deploy_async.py +434 -0
- package/.agent/skills/hf-cloud-sagemaker-production-defaults/scripts/deploy_ic.py +506 -0
- package/.agent/skills/hf-cloud-sagemaker-production-defaults/scripts/invoke_endpoint.py +180 -0
- package/.agent/skills/hf-cloud-sagemaker-production-defaults/scripts/teardown.py +246 -0
- package/.agent/skills/hf-cloud-serving-image-selection/SKILL.md +220 -0
- package/.agent/skills/hf-cloud-serving-image-selection/references/model-to-image.md +111 -0
- package/.agent/skills/hf-cloud-serving-image-selection/scripts/mirror_image.py +145 -0
- package/.agent/skills/hf-mem/SKILL.md +79 -0
- package/.agent/skills/huggingface-best/SKILL.md +134 -0
- package/.agent/skills/huggingface-community-evals/SKILL.md +207 -0
- package/.agent/skills/huggingface-community-evals/examples/.env.example +3 -0
- package/.agent/skills/huggingface-community-evals/examples/USAGE_EXAMPLES.md +101 -0
- package/.agent/skills/huggingface-community-evals/scripts/inspect_eval_uv.py +104 -0
- package/.agent/skills/huggingface-community-evals/scripts/inspect_vllm_uv.py +306 -0
- package/.agent/skills/huggingface-community-evals/scripts/lighteval_vllm_uv.py +297 -0
- package/.agent/skills/huggingface-datasets/SKILL.md +107 -0
- package/.agent/skills/huggingface-gradio/SKILL.md +298 -0
- package/.agent/skills/huggingface-gradio/examples.md +613 -0
- package/.agent/skills/huggingface-llm-trainer/SKILL.md +738 -0
- package/.agent/skills/huggingface-llm-trainer/references/gguf_conversion.md +296 -0
- package/.agent/skills/huggingface-llm-trainer/references/hardware_guide.md +283 -0
- package/.agent/skills/huggingface-llm-trainer/references/hub_saving.md +364 -0
- package/.agent/skills/huggingface-llm-trainer/references/local_training_macos.md +231 -0
- package/.agent/skills/huggingface-llm-trainer/references/reliability_principles.md +371 -0
- package/.agent/skills/huggingface-llm-trainer/references/trackio_guide.md +191 -0
- package/.agent/skills/huggingface-llm-trainer/references/training_methods.md +150 -0
- package/.agent/skills/huggingface-llm-trainer/references/training_patterns.md +203 -0
- package/.agent/skills/huggingface-llm-trainer/references/troubleshooting.md +282 -0
- package/.agent/skills/huggingface-llm-trainer/references/unsloth.md +313 -0
- package/.agent/skills/huggingface-llm-trainer/scripts/convert_to_gguf.py +424 -0
- package/.agent/skills/huggingface-llm-trainer/scripts/dataset_inspector.py +417 -0
- package/.agent/skills/huggingface-llm-trainer/scripts/estimate_cost.py +150 -0
- package/.agent/skills/huggingface-llm-trainer/scripts/hf_benchmarks.py +659 -0
- package/.agent/skills/huggingface-llm-trainer/scripts/train_dpo_example.py +106 -0
- package/.agent/skills/huggingface-llm-trainer/scripts/train_grpo_example.py +89 -0
- package/.agent/skills/huggingface-llm-trainer/scripts/train_sft_example.py +122 -0
- package/.agent/skills/huggingface-llm-trainer/scripts/unsloth_sft_example.py +512 -0
- package/.agent/skills/huggingface-local-models/SKILL.md +113 -0
- package/.agent/skills/huggingface-local-models/references/hardware.md +38 -0
- package/.agent/skills/huggingface-local-models/references/hub-discovery.md +178 -0
- package/.agent/skills/huggingface-local-models/references/quantization.md +256 -0
- package/.agent/skills/huggingface-lora-space-builder/SKILL.md +394 -0
- package/.agent/skills/huggingface-lora-space-builder/references/adapting-to-the-lora.md +113 -0
- package/.agent/skills/huggingface-lora-space-builder/references/base-models/krea-2.md +63 -0
- package/.agent/skills/huggingface-lora-space-builder/references/base-models/ltx.md +205 -0
- package/.agent/skills/huggingface-lora-space-builder/references/base-models/qwen-image.md +144 -0
- package/.agent/skills/huggingface-lora-space-builder/references/creative-mode.md +262 -0
- package/.agent/skills/huggingface-lora-space-builder/references/tasks.md +124 -0
- package/.agent/skills/huggingface-lora-space-builder/references/zerogpu-and-publishing.md +196 -0
- package/.agent/skills/huggingface-paper-publisher/SKILL.md +624 -0
- package/.agent/skills/huggingface-paper-publisher/examples/example_usage.md +326 -0
- package/.agent/skills/huggingface-paper-publisher/references/quick_reference.md +216 -0
- package/.agent/skills/huggingface-paper-publisher/scripts/paper_manager.py +606 -0
- package/.agent/skills/huggingface-paper-publisher/templates/arxiv.md +299 -0
- package/.agent/skills/huggingface-paper-publisher/templates/ml-report.md +358 -0
- package/.agent/skills/huggingface-paper-publisher/templates/modern.md +319 -0
- package/.agent/skills/huggingface-paper-publisher/templates/standard.md +201 -0
- package/.agent/skills/huggingface-papers/SKILL.md +239 -0
- package/.agent/skills/huggingface-spaces/README.md +9 -0
- package/.agent/skills/huggingface-spaces/SKILL.md +242 -0
- package/.agent/skills/huggingface-spaces/references/3d-cuda-extensions.md +109 -0
- package/.agent/skills/huggingface-spaces/references/3d-generation.md +98 -0
- package/.agent/skills/huggingface-spaces/references/3d-gsplat.md +53 -0
- package/.agent/skills/huggingface-spaces/references/3d-models.md +227 -0
- package/.agent/skills/huggingface-spaces/references/3d-outputs.md +114 -0
- package/.agent/skills/huggingface-spaces/references/buckets.md +89 -0
- package/.agent/skills/huggingface-spaces/references/debugging.md +236 -0
- package/.agent/skills/huggingface-spaces/references/gradio.md +200 -0
- package/.agent/skills/huggingface-spaces/references/grants.md +63 -0
- package/.agent/skills/huggingface-spaces/references/inference-providers.md +97 -0
- package/.agent/skills/huggingface-spaces/references/known-errors.md +232 -0
- package/.agent/skills/huggingface-spaces/references/requirements.md +169 -0
- package/.agent/skills/huggingface-spaces/references/zerogpu.md +349 -0
- package/.agent/skills/huggingface-tool-builder/SKILL.md +120 -0
- package/.agent/skills/huggingface-tool-builder/references/baseline_hf_api.py +57 -0
- package/.agent/skills/huggingface-tool-builder/references/baseline_hf_api.sh +40 -0
- package/.agent/skills/huggingface-tool-builder/references/baseline_hf_api.tsx +57 -0
- package/.agent/skills/huggingface-tool-builder/references/find_models_by_paper.sh +230 -0
- package/.agent/skills/huggingface-tool-builder/references/hf_enrich_models.sh +96 -0
- package/.agent/skills/huggingface-tool-builder/references/hf_model_card_frontmatter.sh +188 -0
- package/.agent/skills/huggingface-tool-builder/references/hf_model_papers_auth.sh +171 -0
- package/.agent/skills/huggingface-trackio/SKILL.md +142 -0
- package/.agent/skills/huggingface-trackio/references/alerts.md +196 -0
- package/.agent/skills/huggingface-trackio/references/logging_metrics.md +212 -0
- package/.agent/skills/huggingface-trackio/references/retrieving_metrics.md +251 -0
- package/.agent/skills/huggingface-vision-trainer/SKILL.md +593 -0
- package/.agent/skills/huggingface-vision-trainer/references/finetune_sam2_trainer.md +254 -0
- package/.agent/skills/huggingface-vision-trainer/references/hub_saving.md +618 -0
- package/.agent/skills/huggingface-vision-trainer/references/image_classification_training_notebook.md +279 -0
- package/.agent/skills/huggingface-vision-trainer/references/object_detection_training_notebook.md +700 -0
- package/.agent/skills/huggingface-vision-trainer/references/reliability_principles.md +310 -0
- package/.agent/skills/huggingface-vision-trainer/references/timm_trainer.md +91 -0
- package/.agent/skills/huggingface-vision-trainer/scripts/dataset_inspector.py +814 -0
- package/.agent/skills/huggingface-vision-trainer/scripts/estimate_cost.py +217 -0
- package/.agent/skills/huggingface-vision-trainer/scripts/image_classification_training.py +383 -0
- package/.agent/skills/huggingface-vision-trainer/scripts/object_detection_training.py +710 -0
- package/.agent/skills/huggingface-vision-trainer/scripts/sam_segmentation_training.py +382 -0
- package/.agent/skills/huggingface-zerogpu/SKILL.md +289 -0
- package/.agent/skills/huggingface-zerogpu/references/concurrency.md +79 -0
- package/.agent/skills/huggingface-zerogpu/references/cuda-and-deps.md +66 -0
- package/.agent/skills/huggingface-zerogpu/references/how-quota-works.md +74 -0
- package/.agent/skills/huggingface-zerogpu/references/how-zerogpu-works.md +50 -0
- package/.agent/skills/human-gate-negotiation/SKILL.md +30 -0
- package/.agent/skills/intelligent-routing/SKILL.md +10 -4
- package/.agent/skills/semantic-filesystem-navigation/SKILL.md +24 -0
- package/.agent/skills/session-log-interrogation/SKILL.md +29 -0
- package/.agent/skills/subagent-driven-development/SKILL.md +32 -0
- package/.agent/skills/systematic-debugging/SKILL.md +5 -0
- package/.agent/skills/train-sentence-transformers/SKILL.md +109 -0
- package/.agent/skills/train-sentence-transformers/references/base_model_selection.md +79 -0
- package/.agent/skills/train-sentence-transformers/references/dataset_formats.md +128 -0
- package/.agent/skills/train-sentence-transformers/references/evaluators_cross_encoder.md +116 -0
- package/.agent/skills/train-sentence-transformers/references/evaluators_multi_vector_encoder.md +101 -0
- package/.agent/skills/train-sentence-transformers/references/evaluators_sentence_transformer.md +151 -0
- package/.agent/skills/train-sentence-transformers/references/evaluators_sparse_encoder.md +121 -0
- package/.agent/skills/train-sentence-transformers/references/hardware_guide.md +105 -0
- package/.agent/skills/train-sentence-transformers/references/hf_jobs_execution.md +173 -0
- package/.agent/skills/train-sentence-transformers/references/losses_cross_encoder.md +137 -0
- package/.agent/skills/train-sentence-transformers/references/losses_multi_vector_encoder.md +100 -0
- package/.agent/skills/train-sentence-transformers/references/losses_sentence_transformer.md +246 -0
- package/.agent/skills/train-sentence-transformers/references/losses_sparse_encoder.md +106 -0
- package/.agent/skills/train-sentence-transformers/references/model_architectures.md +178 -0
- package/.agent/skills/train-sentence-transformers/references/prompts_and_instructions.md +160 -0
- package/.agent/skills/train-sentence-transformers/references/training_args.md +270 -0
- package/.agent/skills/train-sentence-transformers/references/troubleshooting.md +225 -0
- package/.agent/skills/train-sentence-transformers/scripts/mine_hard_negatives.py +199 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_cross_encoder_distillation_example.py +254 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_cross_encoder_example.py +253 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_cross_encoder_listwise_example.py +282 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_multi_vector_encoder_example.py +240 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_sentence_transformer_distillation_example.py +303 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_sentence_transformer_example.py +227 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_sentence_transformer_make_multilingual_example.py +308 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_sentence_transformer_matryoshka_example.py +212 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_sentence_transformer_multi_dataset_example.py +258 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_sentence_transformer_static_embedding_example.py +273 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_sentence_transformer_with_lora_example.py +275 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_sparse_encoder_distillation_example.py +262 -0
- package/.agent/skills/train-sentence-transformers/scripts/train_sparse_encoder_example.py +237 -0
- package/.agent/skills/transformers-js/SKILL.md +692 -0
- package/.agent/skills/transformers-js/references/CACHE.md +339 -0
- package/.agent/skills/transformers-js/references/CONFIGURATION.md +438 -0
- package/.agent/skills/transformers-js/references/EXAMPLES.md +620 -0
- package/.agent/skills/transformers-js/references/MODEL_ARCHITECTURES.md +167 -0
- package/.agent/skills/transformers-js/references/MODEL_REGISTRY.md +197 -0
- package/.agent/skills/transformers-js/references/PIPELINE_OPTIONS.md +557 -0
- package/.agent/skills/transformers-js/references/TEXT_GENERATION.md +315 -0
- package/.agent/skills/tribunal-instincts-memory/SKILL.md +31 -0
- package/.agent/skills/trl-training/SKILL.md +318 -0
- package/.agent/workflows/assimilate.md +21 -0
- package/.agent/workflows/audit.md +5 -0
- package/.agent/workflows/generate.md +5 -0
- package/.agent/workflows/htop.md +22 -0
- package/.agent/workflows/marathon.md +5 -0
- package/.agent/workflows/resume.md +20 -0
- package/.agent/workflows/team-mode.md +22 -0
- package/.agents/skills/agent-syscall-guidelines/SKILL.md +25 -0
- package/.agents/skills/agentic-workflows-2026/SKILL.md +8 -0
- package/.agents/skills/agentshield-security/SKILL.md +26 -0
- package/.agents/skills/context-engineering-pro/SKILL.md +7 -0
- package/.agents/skills/fabel-protocol/SKILL.md +5 -0
- package/.agents/skills/graph-engineering/SKILL.md +28 -0
- package/.agents/skills/harness-protocol/SKILL.md +8 -0
- package/.agents/skills/hf-cli/SKILL.md +239 -0
- package/.agents/skills/hf-cloud-aws-context-discovery/SKILL.md +74 -0
- package/.agents/skills/hf-cloud-python-env-setup/SKILL.md +90 -0
- package/.agents/skills/hf-cloud-python-env-setup/requirements.txt +17 -0
- package/.agents/skills/hf-cloud-python-env-setup/scripts/check_versions.py +29 -0
- package/.agents/skills/hf-cloud-python-env-setup/scripts/setup_env.py +143 -0
- package/.agents/skills/hf-cloud-sagemaker-deployment-planner/SKILL.md +90 -0
- package/.agents/skills/hf-cloud-sagemaker-iam-preflight/SKILL.md +102 -0
- package/.agents/skills/hf-cloud-sagemaker-iam-preflight/references/minimum-permissions.json +47 -0
- package/.agents/skills/hf-cloud-sagemaker-iam-preflight/references/trust-policy.json +12 -0
- package/.agents/skills/hf-cloud-sagemaker-iam-preflight/scripts/check_role.py +184 -0
- package/.agents/skills/hf-cloud-sagemaker-iam-preflight/scripts/create_role.py +118 -0
- package/.agents/skills/hf-cloud-sagemaker-production-defaults/SKILL.md +419 -0
- package/.agents/skills/hf-cloud-sagemaker-production-defaults/references/deployment-template.md +59 -0
- package/.agents/skills/hf-cloud-sagemaker-production-defaults/scripts/_common.py +148 -0
- package/.agents/skills/hf-cloud-sagemaker-production-defaults/scripts/deploy.py +327 -0
- package/.agents/skills/hf-cloud-sagemaker-production-defaults/scripts/deploy_async.py +434 -0
- package/.agents/skills/hf-cloud-sagemaker-production-defaults/scripts/deploy_ic.py +506 -0
- package/.agents/skills/hf-cloud-sagemaker-production-defaults/scripts/invoke_endpoint.py +180 -0
- package/.agents/skills/hf-cloud-sagemaker-production-defaults/scripts/teardown.py +246 -0
- package/.agents/skills/hf-cloud-serving-image-selection/SKILL.md +220 -0
- package/.agents/skills/hf-cloud-serving-image-selection/references/model-to-image.md +111 -0
- package/.agents/skills/hf-cloud-serving-image-selection/scripts/mirror_image.py +145 -0
- package/.agents/skills/hf-mem/SKILL.md +79 -0
- package/.agents/skills/huggingface-best/SKILL.md +134 -0
- package/.agents/skills/huggingface-community-evals/SKILL.md +207 -0
- package/.agents/skills/huggingface-community-evals/examples/.env.example +3 -0
- package/.agents/skills/huggingface-community-evals/examples/USAGE_EXAMPLES.md +101 -0
- package/.agents/skills/huggingface-community-evals/scripts/inspect_eval_uv.py +104 -0
- package/.agents/skills/huggingface-community-evals/scripts/inspect_vllm_uv.py +306 -0
- package/.agents/skills/huggingface-community-evals/scripts/lighteval_vllm_uv.py +297 -0
- package/.agents/skills/huggingface-datasets/SKILL.md +107 -0
- package/.agents/skills/huggingface-gradio/SKILL.md +298 -0
- package/.agents/skills/huggingface-gradio/examples.md +613 -0
- package/.agents/skills/huggingface-llm-trainer/SKILL.md +738 -0
- package/.agents/skills/huggingface-llm-trainer/references/gguf_conversion.md +296 -0
- package/.agents/skills/huggingface-llm-trainer/references/hardware_guide.md +283 -0
- package/.agents/skills/huggingface-llm-trainer/references/hub_saving.md +364 -0
- package/.agents/skills/huggingface-llm-trainer/references/local_training_macos.md +231 -0
- package/.agents/skills/huggingface-llm-trainer/references/reliability_principles.md +371 -0
- package/.agents/skills/huggingface-llm-trainer/references/trackio_guide.md +191 -0
- package/.agents/skills/huggingface-llm-trainer/references/training_methods.md +150 -0
- package/.agents/skills/huggingface-llm-trainer/references/training_patterns.md +203 -0
- package/.agents/skills/huggingface-llm-trainer/references/troubleshooting.md +282 -0
- package/.agents/skills/huggingface-llm-trainer/references/unsloth.md +313 -0
- package/.agents/skills/huggingface-llm-trainer/scripts/convert_to_gguf.py +424 -0
- package/.agents/skills/huggingface-llm-trainer/scripts/dataset_inspector.py +417 -0
- package/.agents/skills/huggingface-llm-trainer/scripts/estimate_cost.py +150 -0
- package/.agents/skills/huggingface-llm-trainer/scripts/hf_benchmarks.py +659 -0
- package/.agents/skills/huggingface-llm-trainer/scripts/train_dpo_example.py +106 -0
- package/.agents/skills/huggingface-llm-trainer/scripts/train_grpo_example.py +89 -0
- package/.agents/skills/huggingface-llm-trainer/scripts/train_sft_example.py +122 -0
- package/.agents/skills/huggingface-llm-trainer/scripts/unsloth_sft_example.py +512 -0
- package/.agents/skills/huggingface-local-models/SKILL.md +113 -0
- package/.agents/skills/huggingface-local-models/references/hardware.md +38 -0
- package/.agents/skills/huggingface-local-models/references/hub-discovery.md +178 -0
- package/.agents/skills/huggingface-local-models/references/quantization.md +256 -0
- package/.agents/skills/huggingface-lora-space-builder/SKILL.md +394 -0
- package/.agents/skills/huggingface-lora-space-builder/references/adapting-to-the-lora.md +113 -0
- package/.agents/skills/huggingface-lora-space-builder/references/base-models/krea-2.md +63 -0
- package/.agents/skills/huggingface-lora-space-builder/references/base-models/ltx.md +205 -0
- package/.agents/skills/huggingface-lora-space-builder/references/base-models/qwen-image.md +144 -0
- package/.agents/skills/huggingface-lora-space-builder/references/creative-mode.md +262 -0
- package/.agents/skills/huggingface-lora-space-builder/references/tasks.md +124 -0
- package/.agents/skills/huggingface-lora-space-builder/references/zerogpu-and-publishing.md +196 -0
- package/.agents/skills/huggingface-paper-publisher/SKILL.md +624 -0
- package/.agents/skills/huggingface-paper-publisher/examples/example_usage.md +326 -0
- package/.agents/skills/huggingface-paper-publisher/references/quick_reference.md +216 -0
- package/.agents/skills/huggingface-paper-publisher/scripts/paper_manager.py +606 -0
- package/.agents/skills/huggingface-paper-publisher/templates/arxiv.md +299 -0
- package/.agents/skills/huggingface-paper-publisher/templates/ml-report.md +358 -0
- package/.agents/skills/huggingface-paper-publisher/templates/modern.md +319 -0
- package/.agents/skills/huggingface-paper-publisher/templates/standard.md +201 -0
- package/.agents/skills/huggingface-papers/SKILL.md +239 -0
- package/.agents/skills/huggingface-spaces/README.md +9 -0
- package/.agents/skills/huggingface-spaces/SKILL.md +242 -0
- package/.agents/skills/huggingface-spaces/references/3d-cuda-extensions.md +109 -0
- package/.agents/skills/huggingface-spaces/references/3d-generation.md +98 -0
- package/.agents/skills/huggingface-spaces/references/3d-gsplat.md +53 -0
- package/.agents/skills/huggingface-spaces/references/3d-models.md +227 -0
- package/.agents/skills/huggingface-spaces/references/3d-outputs.md +114 -0
- package/.agents/skills/huggingface-spaces/references/buckets.md +89 -0
- package/.agents/skills/huggingface-spaces/references/debugging.md +236 -0
- package/.agents/skills/huggingface-spaces/references/gradio.md +200 -0
- package/.agents/skills/huggingface-spaces/references/grants.md +63 -0
- package/.agents/skills/huggingface-spaces/references/inference-providers.md +97 -0
- package/.agents/skills/huggingface-spaces/references/known-errors.md +232 -0
- package/.agents/skills/huggingface-spaces/references/requirements.md +169 -0
- package/.agents/skills/huggingface-spaces/references/zerogpu.md +349 -0
- package/.agents/skills/huggingface-tool-builder/SKILL.md +120 -0
- package/.agents/skills/huggingface-tool-builder/references/baseline_hf_api.py +57 -0
- package/.agents/skills/huggingface-tool-builder/references/baseline_hf_api.sh +40 -0
- package/.agents/skills/huggingface-tool-builder/references/baseline_hf_api.tsx +57 -0
- package/.agents/skills/huggingface-tool-builder/references/find_models_by_paper.sh +230 -0
- package/.agents/skills/huggingface-tool-builder/references/hf_enrich_models.sh +96 -0
- package/.agents/skills/huggingface-tool-builder/references/hf_model_card_frontmatter.sh +188 -0
- package/.agents/skills/huggingface-tool-builder/references/hf_model_papers_auth.sh +171 -0
- package/.agents/skills/huggingface-trackio/SKILL.md +142 -0
- package/.agents/skills/huggingface-trackio/references/alerts.md +196 -0
- package/.agents/skills/huggingface-trackio/references/logging_metrics.md +212 -0
- package/.agents/skills/huggingface-trackio/references/retrieving_metrics.md +251 -0
- package/.agents/skills/huggingface-vision-trainer/SKILL.md +593 -0
- package/.agents/skills/huggingface-vision-trainer/references/finetune_sam2_trainer.md +254 -0
- package/.agents/skills/huggingface-vision-trainer/references/hub_saving.md +618 -0
- package/.agents/skills/huggingface-vision-trainer/references/image_classification_training_notebook.md +279 -0
- package/.agents/skills/huggingface-vision-trainer/references/object_detection_training_notebook.md +700 -0
- package/.agents/skills/huggingface-vision-trainer/references/reliability_principles.md +310 -0
- package/.agents/skills/huggingface-vision-trainer/references/timm_trainer.md +91 -0
- package/.agents/skills/huggingface-vision-trainer/scripts/dataset_inspector.py +814 -0
- package/.agents/skills/huggingface-vision-trainer/scripts/estimate_cost.py +217 -0
- package/.agents/skills/huggingface-vision-trainer/scripts/image_classification_training.py +383 -0
- package/.agents/skills/huggingface-vision-trainer/scripts/object_detection_training.py +710 -0
- package/.agents/skills/huggingface-vision-trainer/scripts/sam_segmentation_training.py +382 -0
- package/.agents/skills/huggingface-zerogpu/SKILL.md +289 -0
- package/.agents/skills/huggingface-zerogpu/references/concurrency.md +79 -0
- package/.agents/skills/huggingface-zerogpu/references/cuda-and-deps.md +66 -0
- package/.agents/skills/huggingface-zerogpu/references/how-quota-works.md +74 -0
- package/.agents/skills/huggingface-zerogpu/references/how-zerogpu-works.md +50 -0
- package/.agents/skills/human-gate-negotiation/SKILL.md +30 -0
- package/.agents/skills/intelligent-routing/SKILL.md +10 -4
- package/.agents/skills/semantic-filesystem-navigation/SKILL.md +24 -0
- package/.agents/skills/session-log-interrogation/SKILL.md +29 -0
- package/.agents/skills/subagent-driven-development/SKILL.md +32 -0
- package/.agents/skills/systematic-debugging/SKILL.md +5 -0
- package/.agents/skills/train-sentence-transformers/SKILL.md +109 -0
- package/.agents/skills/train-sentence-transformers/references/base_model_selection.md +79 -0
- package/.agents/skills/train-sentence-transformers/references/dataset_formats.md +128 -0
- package/.agents/skills/train-sentence-transformers/references/evaluators_cross_encoder.md +116 -0
- package/.agents/skills/train-sentence-transformers/references/evaluators_multi_vector_encoder.md +101 -0
- package/.agents/skills/train-sentence-transformers/references/evaluators_sentence_transformer.md +151 -0
- package/.agents/skills/train-sentence-transformers/references/evaluators_sparse_encoder.md +121 -0
- package/.agents/skills/train-sentence-transformers/references/hardware_guide.md +105 -0
- package/.agents/skills/train-sentence-transformers/references/hf_jobs_execution.md +173 -0
- package/.agents/skills/train-sentence-transformers/references/losses_cross_encoder.md +137 -0
- package/.agents/skills/train-sentence-transformers/references/losses_multi_vector_encoder.md +100 -0
- package/.agents/skills/train-sentence-transformers/references/losses_sentence_transformer.md +246 -0
- package/.agents/skills/train-sentence-transformers/references/losses_sparse_encoder.md +106 -0
- package/.agents/skills/train-sentence-transformers/references/model_architectures.md +178 -0
- package/.agents/skills/train-sentence-transformers/references/prompts_and_instructions.md +160 -0
- package/.agents/skills/train-sentence-transformers/references/training_args.md +270 -0
- package/.agents/skills/train-sentence-transformers/references/troubleshooting.md +225 -0
- package/.agents/skills/train-sentence-transformers/scripts/mine_hard_negatives.py +199 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_cross_encoder_distillation_example.py +254 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_cross_encoder_example.py +253 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_cross_encoder_listwise_example.py +282 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_multi_vector_encoder_example.py +240 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_sentence_transformer_distillation_example.py +303 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_sentence_transformer_example.py +227 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_sentence_transformer_make_multilingual_example.py +308 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_sentence_transformer_matryoshka_example.py +212 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_sentence_transformer_multi_dataset_example.py +258 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_sentence_transformer_static_embedding_example.py +273 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_sentence_transformer_with_lora_example.py +275 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_sparse_encoder_distillation_example.py +262 -0
- package/.agents/skills/train-sentence-transformers/scripts/train_sparse_encoder_example.py +237 -0
- package/.agents/skills/transformers-js/SKILL.md +692 -0
- package/.agents/skills/transformers-js/references/CACHE.md +339 -0
- package/.agents/skills/transformers-js/references/CONFIGURATION.md +438 -0
- package/.agents/skills/transformers-js/references/EXAMPLES.md +620 -0
- package/.agents/skills/transformers-js/references/MODEL_ARCHITECTURES.md +167 -0
- package/.agents/skills/transformers-js/references/MODEL_REGISTRY.md +197 -0
- package/.agents/skills/transformers-js/references/PIPELINE_OPTIONS.md +557 -0
- package/.agents/skills/transformers-js/references/TEXT_GENERATION.md +315 -0
- package/.agents/skills/tribunal-instincts-memory/SKILL.md +31 -0
- package/.agents/skills/trl-training/SKILL.md +318 -0
- package/CONTRIBUTING.md +2 -2
- package/README.md +135 -435
- package/bin/adapter-install.js +1 -1
- package/bin/mcp-server.js +5 -5
- package/dist/tui/banner.js +1 -1
- package/gemini-extension.json +1 -1
- package/mcp_config.json +1 -1
- package/package.json +7 -7
- package/plugin.json +1 -1
- package/scripts/context_compiler.js +1 -1
- package/scripts/skill_enhancement_engine.js +6 -6
- package/skills/agent-syscall-guidelines/SKILL.md +25 -0
- package/skills/agentic-workflows-2026/SKILL.md +8 -0
- package/skills/agentshield-security/SKILL.md +26 -0
- package/skills/context-engineering-pro/SKILL.md +7 -0
- package/skills/fabel-protocol/SKILL.md +5 -0
- package/skills/graph-engineering/SKILL.md +28 -0
- package/skills/harness-protocol/SKILL.md +8 -0
- package/skills/hf-cli/SKILL.md +239 -0
- package/skills/hf-cloud-aws-context-discovery/SKILL.md +74 -0
- package/skills/hf-cloud-python-env-setup/SKILL.md +90 -0
- package/skills/hf-cloud-python-env-setup/requirements.txt +17 -0
- package/skills/hf-cloud-python-env-setup/scripts/check_versions.py +29 -0
- package/skills/hf-cloud-python-env-setup/scripts/setup_env.py +143 -0
- package/skills/hf-cloud-sagemaker-deployment-planner/SKILL.md +90 -0
- package/skills/hf-cloud-sagemaker-iam-preflight/SKILL.md +102 -0
- package/skills/hf-cloud-sagemaker-iam-preflight/references/minimum-permissions.json +47 -0
- package/skills/hf-cloud-sagemaker-iam-preflight/references/trust-policy.json +12 -0
- package/skills/hf-cloud-sagemaker-iam-preflight/scripts/check_role.py +184 -0
- package/skills/hf-cloud-sagemaker-iam-preflight/scripts/create_role.py +118 -0
- package/skills/hf-cloud-sagemaker-production-defaults/SKILL.md +419 -0
- package/skills/hf-cloud-sagemaker-production-defaults/references/deployment-template.md +59 -0
- package/skills/hf-cloud-sagemaker-production-defaults/scripts/_common.py +148 -0
- package/skills/hf-cloud-sagemaker-production-defaults/scripts/deploy.py +327 -0
- package/skills/hf-cloud-sagemaker-production-defaults/scripts/deploy_async.py +434 -0
- package/skills/hf-cloud-sagemaker-production-defaults/scripts/deploy_ic.py +506 -0
- package/skills/hf-cloud-sagemaker-production-defaults/scripts/invoke_endpoint.py +180 -0
- package/skills/hf-cloud-sagemaker-production-defaults/scripts/teardown.py +246 -0
- package/skills/hf-cloud-serving-image-selection/SKILL.md +220 -0
- package/skills/hf-cloud-serving-image-selection/references/model-to-image.md +111 -0
- package/skills/hf-cloud-serving-image-selection/scripts/mirror_image.py +145 -0
- package/skills/hf-mem/SKILL.md +79 -0
- package/skills/huggingface-best/SKILL.md +134 -0
- package/skills/huggingface-community-evals/SKILL.md +207 -0
- package/skills/huggingface-community-evals/examples/.env.example +3 -0
- package/skills/huggingface-community-evals/examples/USAGE_EXAMPLES.md +101 -0
- package/skills/huggingface-community-evals/scripts/inspect_eval_uv.py +104 -0
- package/skills/huggingface-community-evals/scripts/inspect_vllm_uv.py +306 -0
- package/skills/huggingface-community-evals/scripts/lighteval_vllm_uv.py +297 -0
- package/skills/huggingface-datasets/SKILL.md +107 -0
- package/skills/huggingface-gradio/SKILL.md +298 -0
- package/skills/huggingface-gradio/examples.md +613 -0
- package/skills/huggingface-llm-trainer/SKILL.md +738 -0
- package/skills/huggingface-llm-trainer/references/gguf_conversion.md +296 -0
- package/skills/huggingface-llm-trainer/references/hardware_guide.md +283 -0
- package/skills/huggingface-llm-trainer/references/hub_saving.md +364 -0
- package/skills/huggingface-llm-trainer/references/local_training_macos.md +231 -0
- package/skills/huggingface-llm-trainer/references/reliability_principles.md +371 -0
- package/skills/huggingface-llm-trainer/references/trackio_guide.md +191 -0
- package/skills/huggingface-llm-trainer/references/training_methods.md +150 -0
- package/skills/huggingface-llm-trainer/references/training_patterns.md +203 -0
- package/skills/huggingface-llm-trainer/references/troubleshooting.md +282 -0
- package/skills/huggingface-llm-trainer/references/unsloth.md +313 -0
- package/skills/huggingface-llm-trainer/scripts/convert_to_gguf.py +424 -0
- package/skills/huggingface-llm-trainer/scripts/dataset_inspector.py +417 -0
- package/skills/huggingface-llm-trainer/scripts/estimate_cost.py +150 -0
- package/skills/huggingface-llm-trainer/scripts/hf_benchmarks.py +659 -0
- package/skills/huggingface-llm-trainer/scripts/train_dpo_example.py +106 -0
- package/skills/huggingface-llm-trainer/scripts/train_grpo_example.py +89 -0
- package/skills/huggingface-llm-trainer/scripts/train_sft_example.py +122 -0
- package/skills/huggingface-llm-trainer/scripts/unsloth_sft_example.py +512 -0
- package/skills/huggingface-local-models/SKILL.md +113 -0
- package/skills/huggingface-local-models/references/hardware.md +38 -0
- package/skills/huggingface-local-models/references/hub-discovery.md +178 -0
- package/skills/huggingface-local-models/references/quantization.md +256 -0
- package/skills/huggingface-lora-space-builder/SKILL.md +394 -0
- package/skills/huggingface-lora-space-builder/references/adapting-to-the-lora.md +113 -0
- package/skills/huggingface-lora-space-builder/references/base-models/krea-2.md +63 -0
- package/skills/huggingface-lora-space-builder/references/base-models/ltx.md +205 -0
- package/skills/huggingface-lora-space-builder/references/base-models/qwen-image.md +144 -0
- package/skills/huggingface-lora-space-builder/references/creative-mode.md +262 -0
- package/skills/huggingface-lora-space-builder/references/tasks.md +124 -0
- package/skills/huggingface-lora-space-builder/references/zerogpu-and-publishing.md +196 -0
- package/skills/huggingface-paper-publisher/SKILL.md +624 -0
- package/skills/huggingface-paper-publisher/examples/example_usage.md +326 -0
- package/skills/huggingface-paper-publisher/references/quick_reference.md +216 -0
- package/skills/huggingface-paper-publisher/scripts/paper_manager.py +606 -0
- package/skills/huggingface-paper-publisher/templates/arxiv.md +299 -0
- package/skills/huggingface-paper-publisher/templates/ml-report.md +358 -0
- package/skills/huggingface-paper-publisher/templates/modern.md +319 -0
- package/skills/huggingface-paper-publisher/templates/standard.md +201 -0
- package/skills/huggingface-papers/SKILL.md +239 -0
- package/skills/huggingface-spaces/README.md +9 -0
- package/skills/huggingface-spaces/SKILL.md +242 -0
- package/skills/huggingface-spaces/references/3d-cuda-extensions.md +109 -0
- package/skills/huggingface-spaces/references/3d-generation.md +98 -0
- package/skills/huggingface-spaces/references/3d-gsplat.md +53 -0
- package/skills/huggingface-spaces/references/3d-models.md +227 -0
- package/skills/huggingface-spaces/references/3d-outputs.md +114 -0
- package/skills/huggingface-spaces/references/buckets.md +89 -0
- package/skills/huggingface-spaces/references/debugging.md +236 -0
- package/skills/huggingface-spaces/references/gradio.md +200 -0
- package/skills/huggingface-spaces/references/grants.md +63 -0
- package/skills/huggingface-spaces/references/inference-providers.md +97 -0
- package/skills/huggingface-spaces/references/known-errors.md +232 -0
- package/skills/huggingface-spaces/references/requirements.md +169 -0
- package/skills/huggingface-spaces/references/zerogpu.md +349 -0
- package/skills/huggingface-tool-builder/SKILL.md +120 -0
- package/skills/huggingface-tool-builder/references/baseline_hf_api.py +57 -0
- package/skills/huggingface-tool-builder/references/baseline_hf_api.sh +40 -0
- package/skills/huggingface-tool-builder/references/baseline_hf_api.tsx +57 -0
- package/skills/huggingface-tool-builder/references/find_models_by_paper.sh +230 -0
- package/skills/huggingface-tool-builder/references/hf_enrich_models.sh +96 -0
- package/skills/huggingface-tool-builder/references/hf_model_card_frontmatter.sh +188 -0
- package/skills/huggingface-tool-builder/references/hf_model_papers_auth.sh +171 -0
- package/skills/huggingface-trackio/SKILL.md +142 -0
- package/skills/huggingface-trackio/references/alerts.md +196 -0
- package/skills/huggingface-trackio/references/logging_metrics.md +212 -0
- package/skills/huggingface-trackio/references/retrieving_metrics.md +251 -0
- package/skills/huggingface-vision-trainer/SKILL.md +593 -0
- package/skills/huggingface-vision-trainer/references/finetune_sam2_trainer.md +254 -0
- package/skills/huggingface-vision-trainer/references/hub_saving.md +618 -0
- package/skills/huggingface-vision-trainer/references/image_classification_training_notebook.md +279 -0
- package/skills/huggingface-vision-trainer/references/object_detection_training_notebook.md +700 -0
- package/skills/huggingface-vision-trainer/references/reliability_principles.md +310 -0
- package/skills/huggingface-vision-trainer/references/timm_trainer.md +91 -0
- package/skills/huggingface-vision-trainer/scripts/dataset_inspector.py +814 -0
- package/skills/huggingface-vision-trainer/scripts/estimate_cost.py +217 -0
- package/skills/huggingface-vision-trainer/scripts/image_classification_training.py +383 -0
- package/skills/huggingface-vision-trainer/scripts/object_detection_training.py +710 -0
- package/skills/huggingface-vision-trainer/scripts/sam_segmentation_training.py +382 -0
- package/skills/huggingface-zerogpu/SKILL.md +289 -0
- package/skills/huggingface-zerogpu/references/concurrency.md +79 -0
- package/skills/huggingface-zerogpu/references/cuda-and-deps.md +66 -0
- package/skills/huggingface-zerogpu/references/how-quota-works.md +74 -0
- package/skills/huggingface-zerogpu/references/how-zerogpu-works.md +50 -0
- package/skills/human-gate-negotiation/SKILL.md +30 -0
- package/skills/intelligent-routing/SKILL.md +10 -4
- package/skills/semantic-filesystem-navigation/SKILL.md +24 -0
- package/skills/session-log-interrogation/SKILL.md +29 -0
- package/skills/subagent-driven-development/SKILL.md +32 -0
- package/skills/systematic-debugging/SKILL.md +5 -0
- package/skills/train-sentence-transformers/SKILL.md +109 -0
- package/skills/train-sentence-transformers/references/base_model_selection.md +79 -0
- package/skills/train-sentence-transformers/references/dataset_formats.md +128 -0
- package/skills/train-sentence-transformers/references/evaluators_cross_encoder.md +116 -0
- package/skills/train-sentence-transformers/references/evaluators_multi_vector_encoder.md +101 -0
- package/skills/train-sentence-transformers/references/evaluators_sentence_transformer.md +151 -0
- package/skills/train-sentence-transformers/references/evaluators_sparse_encoder.md +121 -0
- package/skills/train-sentence-transformers/references/hardware_guide.md +105 -0
- package/skills/train-sentence-transformers/references/hf_jobs_execution.md +173 -0
- package/skills/train-sentence-transformers/references/losses_cross_encoder.md +137 -0
- package/skills/train-sentence-transformers/references/losses_multi_vector_encoder.md +100 -0
- package/skills/train-sentence-transformers/references/losses_sentence_transformer.md +246 -0
- package/skills/train-sentence-transformers/references/losses_sparse_encoder.md +106 -0
- package/skills/train-sentence-transformers/references/model_architectures.md +178 -0
- package/skills/train-sentence-transformers/references/prompts_and_instructions.md +160 -0
- package/skills/train-sentence-transformers/references/training_args.md +270 -0
- package/skills/train-sentence-transformers/references/troubleshooting.md +225 -0
- package/skills/train-sentence-transformers/scripts/mine_hard_negatives.py +199 -0
- package/skills/train-sentence-transformers/scripts/train_cross_encoder_distillation_example.py +254 -0
- package/skills/train-sentence-transformers/scripts/train_cross_encoder_example.py +253 -0
- package/skills/train-sentence-transformers/scripts/train_cross_encoder_listwise_example.py +282 -0
- package/skills/train-sentence-transformers/scripts/train_multi_vector_encoder_example.py +240 -0
- package/skills/train-sentence-transformers/scripts/train_sentence_transformer_distillation_example.py +303 -0
- package/skills/train-sentence-transformers/scripts/train_sentence_transformer_example.py +227 -0
- package/skills/train-sentence-transformers/scripts/train_sentence_transformer_make_multilingual_example.py +308 -0
- package/skills/train-sentence-transformers/scripts/train_sentence_transformer_matryoshka_example.py +212 -0
- package/skills/train-sentence-transformers/scripts/train_sentence_transformer_multi_dataset_example.py +258 -0
- package/skills/train-sentence-transformers/scripts/train_sentence_transformer_static_embedding_example.py +273 -0
- package/skills/train-sentence-transformers/scripts/train_sentence_transformer_with_lora_example.py +275 -0
- package/skills/train-sentence-transformers/scripts/train_sparse_encoder_distillation_example.py +262 -0
- package/skills/train-sentence-transformers/scripts/train_sparse_encoder_example.py +237 -0
- package/skills/transformers-js/SKILL.md +692 -0
- package/skills/transformers-js/references/CACHE.md +339 -0
- package/skills/transformers-js/references/CONFIGURATION.md +438 -0
- package/skills/transformers-js/references/EXAMPLES.md +620 -0
- package/skills/transformers-js/references/MODEL_ARCHITECTURES.md +167 -0
- package/skills/transformers-js/references/MODEL_REGISTRY.md +197 -0
- package/skills/transformers-js/references/PIPELINE_OPTIONS.md +557 -0
- package/skills/transformers-js/references/TEXT_GENERATION.md +315 -0
- package/skills/tribunal-instincts-memory/SKILL.md +31 -0
- package/skills/trl-training/SKILL.md +318 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Hardware Guide
|
|
2
|
+
|
|
3
|
+
Training embedding models is memory-bound more often than compute-bound.
|
|
4
|
+
|
|
5
|
+
## If you hit OOM
|
|
6
|
+
|
|
7
|
+
Try in this order:
|
|
8
|
+
|
|
9
|
+
1. **Reduce `per_device_train_batch_size`**. Raise `gradient_accumulation_steps` to keep the effective batch size for regression losses. (For MNRL, effective batch via grad-accum is **not** equivalent. See point 3.)
|
|
10
|
+
2. **Enable `gradient_checkpointing=True`**. ~30% slower, ~40% less activation memory. Incompatible with `Cached*` losses.
|
|
11
|
+
3. **Switch to a `Cached*` loss**:
|
|
12
|
+
- `CachedMultipleNegativesRankingLoss(model, mini_batch_size=32)`: forwards in mini-batches, accumulates the contrastive loss over the full batch. Can simulate batch sizes of 1024+ on a 24GB GPU.
|
|
13
|
+
- `CachedSpladeLoss(model, loss=..., mini_batch_size=16)`: same trick for sparse.
|
|
14
|
+
- `CachedGISTEmbedLoss(model, guide_model, mini_batch_size=32)`: GIST variant.
|
|
15
|
+
4. **Enable PEFT / LoRA** for decoder models >1B. `LoraConfig(r=64, lora_alpha=128, task_type="FEATURE_EXTRACTION")`. See `../scripts/train_sentence_transformer_with_lora_example.py` (docstring covers when to use, hyperparams, QLoRA, sharing).
|
|
16
|
+
5. **Move to multi-GPU**. See below.
|
|
17
|
+
6. **Shorten sequences**. If truncating to 128 is already sufficient for your task, set `max_seq_length` on the transformer module.
|
|
18
|
+
|
|
19
|
+
## Multi-GPU
|
|
20
|
+
|
|
21
|
+
`sentence-transformers` uses `accelerate` under the hood. Distributed training works without code changes.
|
|
22
|
+
|
|
23
|
+
### Data parallel (DDP)
|
|
24
|
+
|
|
25
|
+
Launch:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
accelerate launch train.py
|
|
29
|
+
|
|
30
|
+
# or explicitly:
|
|
31
|
+
accelerate launch --multi_gpu --num_processes=4 train.py
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`per_device_train_batch_size` stays per-GPU. Effective batch size scales linearly. MNRL's in-batch negatives remain **per-device**, not global, unless you pass `gather_across_devices=True` to losses that support it (`MultipleNegativesRankingLoss`, `CachedMultipleNegativesRankingLoss`, the symmetric variants, `GISTEmbedLoss`, `CachedGISTEmbedLoss`, `SparseMultipleNegativesRankingLoss`).
|
|
35
|
+
|
|
36
|
+
### FSDP / DeepSpeed
|
|
37
|
+
|
|
38
|
+
For models >3B, use `accelerate config` to enable FSDP or DeepSpeed ZeRO. Both are supported: `sentence-transformers` doesn't require any code changes, only the launch config.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
accelerate config # interactive; choose FSDP or DeepSpeed
|
|
42
|
+
accelerate launch train.py
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
With FSDP full-shard: a 7B model trains on 4×24GB GPUs that would OOM on any single one of them.
|
|
46
|
+
|
|
47
|
+
**FSDP caveats** (from the [distributed training docs](https://sbert.net/docs/sentence_transformer/training/distributed.html)):
|
|
48
|
+
- **Evaluators don't run under FSDP** as of writing: the eval hooks call `model.encode()` which FSDP-wrapped modules can't service mid-training. Plan to evaluate post-training on a single-GPU load of the final checkpoint instead, or train with DDP if you need mid-training evaluation.
|
|
49
|
+
- **Layer wrapping must be specified**, e.g. `fsdp_config={"transformer_layer_cls_to_wrap": "BertLayer"}` (substitute the right layer class for your model: `BertLayer`, `LlamaDecoderLayer`, `Qwen2DecoderLayer`, etc.). Without this FSDP sharding can silently misbehave.
|
|
50
|
+
- **Slower than DDP** for models that fit on a single GPU. Only reach for FSDP when you actually need the memory savings.
|
|
51
|
+
|
|
52
|
+
DeepSpeed ZeRO-2/3 is an alternative with its own config. It works identically at the `accelerate config` level.
|
|
53
|
+
|
|
54
|
+
## Effective batch size for contrastive losses
|
|
55
|
+
|
|
56
|
+
For `MultipleNegativesRankingLoss` and its variants, **batch size is a quality knob**, not just a speed knob. Bigger batches = more in-batch negatives = richer gradients.
|
|
57
|
+
|
|
58
|
+
The effective pool of in-batch negatives per anchor:
|
|
59
|
+
|
|
60
|
+
| Setup | In-batch negatives per anchor |
|
|
61
|
+
|---|---|
|
|
62
|
+
| Single GPU, batch 64 | 63 |
|
|
63
|
+
| 4× DDP, per-device batch 64 | 63 local only by default. 255 with `MultipleNegativesRankingLoss(model, gather_across_devices=True)` |
|
|
64
|
+
| Single GPU, CachedMNRL, mini_batch 32, batch 256 | 255 |
|
|
65
|
+
| 4× DDP, CachedMNRL, per-device 256 | 255 local. 1023 with `gather_across_devices=True` |
|
|
66
|
+
|
|
67
|
+
For large corpora (retrieval), push toward 512+ effective negatives. For small, clean datasets (STS), 64 is plenty.
|
|
68
|
+
|
|
69
|
+
## Precision choice by GPU
|
|
70
|
+
|
|
71
|
+
| GPU generation | Recommended |
|
|
72
|
+
|---|---|
|
|
73
|
+
| T4, V100, GTX 1xxx, RTX 2xxx | `fp16=True` |
|
|
74
|
+
| RTX 3xxx, A10G, A100, L4 | `bf16=True` |
|
|
75
|
+
| RTX 4xxx, H100, B200 | `bf16=True` (or fp8 on H100 via specific kernels, not default) |
|
|
76
|
+
| Apple M-series / ROCm | MPS/ROCm support is variable. `fp16` or `fp32` most reliable |
|
|
77
|
+
|
|
78
|
+
bf16 is more numerically stable and almost always preferred when available.
|
|
79
|
+
|
|
80
|
+
## Hugging Face Jobs flavor guide
|
|
81
|
+
|
|
82
|
+
Hugging Face Jobs requires a Pro/Team/Enterprise plan. Pricing is approximate and subject to change. See the [Jobs pricing page](https://huggingface.co/docs/huggingface_hub/guides/jobs).
|
|
83
|
+
|
|
84
|
+
| Flavor | Memory | Typical use | Est. $/hr |
|
|
85
|
+
|---|---|---|---|
|
|
86
|
+
| `cpu-basic` | ~2 GB | Dataset prep, validation, hard-neg mining (small) | <$0.10 |
|
|
87
|
+
| `cpu-upgrade` | ~4 GB | Same, slightly bigger | $0.10 |
|
|
88
|
+
| `t4-small` | 16 GB | Demos, MiniLM/DistilBERT with small batches | ~$0.75 |
|
|
89
|
+
| `t4-medium` | 16 GB | MiniLM / DistilBERT with larger batch | ~$1.50 |
|
|
90
|
+
| `l4x1` | 24 GB | BERT-base, MPNet, ModernBERT-base | ~$2.50 |
|
|
91
|
+
| `a10g-small` | 24 GB | BERT-base to BERT-large | ~$3.50 |
|
|
92
|
+
| `a10g-large` | 48 GB | ModernBERT-large, Qwen3-0.6B | ~$5.00 |
|
|
93
|
+
| `a10g-largex2` | 96 GB (2× 48GB) | Mid-size multi-GPU | ~$10 |
|
|
94
|
+
| `a100-large` | 80 GB | Large models or big contrastive batches | ~$10-12 |
|
|
95
|
+
| `h100` | 80 GB | Biggest single-GPU | ~$12 |
|
|
96
|
+
| `h100x8` | 640 GB | LLM-scale distributed | ~$96 |
|
|
97
|
+
|
|
98
|
+
Defaults by base model:
|
|
99
|
+
- MiniLM / DistilBERT -> `t4-small`
|
|
100
|
+
- BERT-base / MPNet / ModernBERT-base -> `a10g-small` or `l4x1`
|
|
101
|
+
- BERT-large / ModernBERT-large -> `a10g-large`
|
|
102
|
+
- Qwen3-0.6B decoder base -> `a10g-large`
|
|
103
|
+
- 1B+ decoder bases with LoRA -> `a10g-large` or `a100-large`
|
|
104
|
+
|
|
105
|
+
Always start one flavor **smaller** than you think you need: OOM on Jobs is cheap ($0.50-$5 for a failed run). Underprovisioned is better than overprovisioned for the first attempt. When budgeting `timeout`, add **20-30% buffer** for model loading, checkpoint saving, and Hub push.
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Hugging Face Jobs Execution
|
|
2
|
+
|
|
3
|
+
Run training on Hugging Face's managed GPUs without provisioning any local infrastructure. The same training script runs locally and on Jobs. This reference covers only the Jobs-specific concerns.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Hugging Face account with a **Pro, Team, or Enterprise** plan. Jobs are paid.
|
|
8
|
+
- `HF_TOKEN` with **write** permission. Log in once locally with `hf auth login` (the modern command from the `hf` CLI, replacing the deprecated `huggingface-cli login`).
|
|
9
|
+
- Access to the `hf_jobs()` MCP tool, or the `hf` CLI (`curl -LsSf https://hf.co/cli/install.sh | bash -s`).
|
|
10
|
+
|
|
11
|
+
## The three submission paths
|
|
12
|
+
|
|
13
|
+
### 1. Inline script via MCP (recommended in Claude Code)
|
|
14
|
+
|
|
15
|
+
Pass the full training script as `script`. Dependencies come from the PEP 723 header.
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
hf_jobs("uv", {
|
|
19
|
+
"script": """
|
|
20
|
+
# /// script
|
|
21
|
+
# requires-python = ">=3.10"
|
|
22
|
+
# dependencies = ["sentence-transformers[train]>=5.0", "trackio"]
|
|
23
|
+
# ///
|
|
24
|
+
|
|
25
|
+
# <full training script content>
|
|
26
|
+
""",
|
|
27
|
+
"flavor": "a10g-large",
|
|
28
|
+
"timeout": "3h",
|
|
29
|
+
"secrets": {"HF_TOKEN": "$HF_TOKEN"},
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Script-from-URL via MCP
|
|
34
|
+
|
|
35
|
+
Upload the script to the Hub (as a model or dataset repo file) or a Gist, then reference by URL:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
hf_jobs("uv", {
|
|
39
|
+
"script": "https://huggingface.co/USERNAME/scripts/resolve/main/train_bi_encoder.py",
|
|
40
|
+
"flavor": "a10g-large",
|
|
41
|
+
"timeout": "3h",
|
|
42
|
+
"secrets": {"HF_TOKEN": "$HF_TOKEN"},
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Local file paths (`./train.py`, `/path/to/train.py`) **do not work**. Jobs run in isolated containers without access to your filesystem.
|
|
47
|
+
|
|
48
|
+
### 3. CLI
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
hf jobs uv run \
|
|
52
|
+
--flavor a10g-large \
|
|
53
|
+
--timeout 3h \
|
|
54
|
+
--secrets HF_TOKEN \
|
|
55
|
+
"https://huggingface.co/USERNAME/scripts/resolve/main/train.py"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Syntax gotchas:
|
|
59
|
+
- Command order is `hf jobs uv run`, **not** `hf jobs run uv`.
|
|
60
|
+
- Flags (`--flavor`, `--timeout`, `--secrets`) go **before** the script URL.
|
|
61
|
+
- `--secrets` (plural), not `--secret`.
|
|
62
|
+
|
|
63
|
+
## Required script modifications for Jobs
|
|
64
|
+
|
|
65
|
+
Add these to your `TrainingArguments`:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
args = SentenceTransformerTrainingArguments(
|
|
69
|
+
...,
|
|
70
|
+
push_to_hub=True,
|
|
71
|
+
hub_model_id="your-username/my-model",
|
|
72
|
+
hub_strategy="every_save", # push each checkpoint; timeout-safe
|
|
73
|
+
save_strategy="steps",
|
|
74
|
+
save_steps=0.1, # 10 saves/pushes per epoch; scales with dataset size
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Why each matters:
|
|
79
|
+
|
|
80
|
+
| Argument | Why |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `push_to_hub=True` | The Jobs container is destroyed after the job finishes. Without Hub push, all weights are lost. |
|
|
83
|
+
| `hub_model_id` | Required to identify the destination repo. |
|
|
84
|
+
| `hub_strategy="every_save"` | Default, but worth being deliberate about on Jobs: each checkpoint is pushed as it's written, so a timeout leaves all completed checkpoints on the Hub. `"end"` only pushes once `trainer.train()` returns, so a timeout loses everything. |
|
|
85
|
+
| `save_strategy="steps"` + `save_steps=0.1` | Checkpoints must actually be saved for `hub_strategy="every_save"` to push them. Fractional `0.1` = save every 10% of training, auto-scales with dataset size. |
|
|
86
|
+
|
|
87
|
+
## Secrets
|
|
88
|
+
|
|
89
|
+
Secrets are environment variables injected into the Jobs container. They never appear in logs and are not part of the script.
|
|
90
|
+
|
|
91
|
+
| Secret | Required when |
|
|
92
|
+
|---|---|
|
|
93
|
+
| `HF_TOKEN` | Always, for Hub push. Also covers Trackio auth. |
|
|
94
|
+
| `WANDB_API_KEY` | Using `report_to="wandb"`. |
|
|
95
|
+
| `MLFLOW_TRACKING_URI`, `MLFLOW_TRACKING_TOKEN` | Using MLflow with a remote server. |
|
|
96
|
+
|
|
97
|
+
The `$HF_TOKEN` syntax in the job config references the value from your local environment at submission time. The literal string `$HF_TOKEN` is replaced with your token's value. Never hardcode tokens in the script itself.
|
|
98
|
+
|
|
99
|
+
Trackio (the default tracker in this skill) uses `HF_TOKEN` for auth, so no extra secrets are needed. Only switch to the W&B / MLflow rows above if you're using those trackers.
|
|
100
|
+
|
|
101
|
+
## Timeout
|
|
102
|
+
|
|
103
|
+
Default is **30 minutes**, which is too short for almost any real training. Set explicitly:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
"timeout": "2h" # 2 hours
|
|
107
|
+
"timeout": "90m" # 90 minutes
|
|
108
|
+
"timeout": "1.5h" # 90 minutes
|
|
109
|
+
"timeout": 7200 # seconds, as integer
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Rule: **estimated training time × 1.3**. The extra buffer covers model loading, dataset caching, checkpoint saving, and Hub push.
|
|
113
|
+
|
|
114
|
+
On timeout, the container is killed immediately. Only data on the Hub (`hub_strategy="every_save"` saves you here) or in persistent volumes survives.
|
|
115
|
+
|
|
116
|
+
## Dataset caching
|
|
117
|
+
|
|
118
|
+
Hugging Face datasets are cached at `~/.cache/huggingface/datasets` by default. That's **inside the container**, which is destroyed after the job. Each Jobs run re-downloads the dataset.
|
|
119
|
+
|
|
120
|
+
For large datasets (>5 GB), this matters. Options:
|
|
121
|
+
|
|
122
|
+
- **Persistent `/data` volume** (Jobs feature, check current documentation): set `HF_DATASETS_CACHE=/data/datasets` so caches persist across jobs.
|
|
123
|
+
- **Pre-cache locally, push to Hub**: if the dataset is on Hub already, nothing to do. If it's local-only, `dataset.push_to_hub(...)` once so subsequent jobs load from Hub.
|
|
124
|
+
|
|
125
|
+
## Monitoring a running job
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
hf jobs ps [--all] # running (or all) jobs
|
|
129
|
+
hf jobs inspect <job-id> # full config + status
|
|
130
|
+
hf jobs logs <job-id> [--follow|--tail N] # tail or stream
|
|
131
|
+
hf jobs cancel <job-id>
|
|
132
|
+
hf jobs hardware # list flavors + hourly rates
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`hf jobs logs <id> --follow` under `Bash run_in_background` pairs nicely with a `Monitor` watching for the `VERDICT:` line emitted by your training script's verdict block.
|
|
136
|
+
|
|
137
|
+
MCP equivalents (signatures may vary by server version, so check the actual
|
|
138
|
+
tool listing): `hf_jobs("ps")`, `hf_jobs("logs", {"job_id": ...})`,
|
|
139
|
+
`hf_jobs("cancel", {"job_id": ...})`.
|
|
140
|
+
|
|
141
|
+
For recurring runs, `hf jobs scheduled uv run "<cron>" <script> ...`
|
|
142
|
+
schedules. `hf jobs scheduled ps/suspend/delete` manages.
|
|
143
|
+
|
|
144
|
+
## Common failures
|
|
145
|
+
|
|
146
|
+
### "Model not found on Hub" after a successful-looking run
|
|
147
|
+
|
|
148
|
+
The run succeeded but `push_to_hub` was not enabled. The container is gone. The weights are gone.
|
|
149
|
+
|
|
150
|
+
Fix: always set `push_to_hub=True` + `hub_model_id=...` + `secrets={"HF_TOKEN": "$HF_TOKEN"}`.
|
|
151
|
+
|
|
152
|
+
### Tracker not connecting
|
|
153
|
+
|
|
154
|
+
- **Trackio:** `HF_TOKEN` missing or lacks write permission. Add `"secrets": {"HF_TOKEN": "$HF_TOKEN"}` and make sure the token has write access.
|
|
155
|
+
- **W&B:** `WANDB_API_KEY` missing. Add `"secrets": {"HF_TOKEN": "$HF_TOKEN", "WANDB_API_KEY": "$WANDB_API_KEY"}`.
|
|
156
|
+
|
|
157
|
+
### OOM on first step
|
|
158
|
+
|
|
159
|
+
Flavor too small. Move up one tier (see `hardware_guide.md`).
|
|
160
|
+
|
|
161
|
+
### Training starts but eval hangs forever
|
|
162
|
+
|
|
163
|
+
`eval_strategy="steps"` with no `eval_dataset`. Always provide an eval dataset, or set `eval_strategy="no"`.
|
|
164
|
+
|
|
165
|
+
### Dataset download times out
|
|
166
|
+
|
|
167
|
+
Large dataset or slow cold-cache. Increase `timeout` or pre-cache to a persistent volume.
|
|
168
|
+
|
|
169
|
+
### `CachedMultipleNegativesRankingLoss` + `gradient_checkpointing=True` crash
|
|
170
|
+
|
|
171
|
+
The cached losses are incompatible with gradient checkpointing. Disable `gradient_checkpointing`.
|
|
172
|
+
|
|
173
|
+
After submission, the MCP returns a job ID. Monitor with `hf_jobs("logs", {"job_id": ...})` when you want an update. Don't poll in a tight loop. End-to-end submission templates live in `scripts/train_sentence_transformer_example.py` / `scripts/train_cross_encoder_example.py` / `scripts/train_sparse_encoder_example.py`. Wrap the script contents in the inline pattern from §1 above.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Cross-Encoder Losses (reranker)
|
|
2
|
+
|
|
3
|
+
All losses live in `sentence_transformers.cross_encoder.losses`.
|
|
4
|
+
|
|
5
|
+
Cross-encoder losses fall into three families: **pointwise** (score each pair independently), **pairwise** (score pairs of pairs), and **listwise** (score a whole ranked list at once). Plus contrastive/distillation variants for specific setups.
|
|
6
|
+
|
|
7
|
+
## Top-line decision table
|
|
8
|
+
|
|
9
|
+
| You have | Use | Family |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `(query, passage, label)` with `label ∈ {0, 1}` or `[0, 1]` | `BinaryCrossEntropyLoss` | Pointwise |
|
|
12
|
+
| `(query, passage, class_id)` multi-class | `CrossEntropyLoss` | Pointwise |
|
|
13
|
+
| `(query, passage)` with implicit positives, want contrastive | `CachedMultipleNegativesRankingLoss` | Contrastive |
|
|
14
|
+
| `(query, passages, labels)` (one row per query, with parallel lists of candidate passages and their relevance scores) | `LambdaLoss` | Listwise |
|
|
15
|
+
| Same listwise shape, want well-tested simpler loss | `ListNetLoss` or `ListMLELoss` | Listwise |
|
|
16
|
+
| `(query, positive, negative)` pairwise | `RankNetLoss` | Pairwise |
|
|
17
|
+
| `(query, passage, teacher_score)` distillation from stronger reranker | `MSELoss` or `MarginMSELoss` | Distillation |
|
|
18
|
+
|
|
19
|
+
## Pointwise losses
|
|
20
|
+
|
|
21
|
+
### `BinaryCrossEntropyLoss`
|
|
22
|
+
|
|
23
|
+
**The default cross-encoder loss.** For `(query, passage, label)` where label is 0/1 or a continuous [0, 1] relevance score.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
loss = BinaryCrossEntropyLoss(model, pos_weight=torch.tensor(5.0))
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- `pos_weight`: upweight positives when your dataset is imbalanced (e.g. 1 positive + N hard negatives). A good default is `pos_weight = num_hard_negatives`.
|
|
30
|
+
- Handles both binary labels and continuous relevance scores. If you have graded relevance (0.0, 0.5, 1.0), BCE still works.
|
|
31
|
+
|
|
32
|
+
### `CrossEntropyLoss`
|
|
33
|
+
|
|
34
|
+
Multi-class classification over passages. Use with `CrossEncoder("...", num_labels=N)` where N is the number of classes (e.g. 3 for NLI: entailment / neutral / contradiction).
|
|
35
|
+
|
|
36
|
+
## Contrastive losses (for reranker training)
|
|
37
|
+
|
|
38
|
+
### `MultipleNegativesRankingLoss` (cross-encoder)
|
|
39
|
+
|
|
40
|
+
Contrastive training mirroring bi-encoder MNRL. Applies in-batch negatives: for each `(query, positive)`, every other `positive` in the batch is used as a negative.
|
|
41
|
+
|
|
42
|
+
- **Data**: `(query, positive)` or `(query, positive, negative_0, negative_1, ...)`.
|
|
43
|
+
- For CrossEncoder training, **prefer `BinaryCrossEntropyLoss` with mined hard negatives** as the default. MNRL is the fallback when you only have `(query, positive)` pairs and want to avoid a separate mining pass.
|
|
44
|
+
|
|
45
|
+
### `CachedMultipleNegativesRankingLoss`
|
|
46
|
+
|
|
47
|
+
Cached variant (GradCache). Decouples per-device batch size from effective in-batch negatives, same as the bi-encoder cached version.
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
loss = CachedMultipleNegativesRankingLoss(model, mini_batch_size=16)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- Incompatible with `gradient_checkpointing=True`.
|
|
54
|
+
- Key choice for training rerankers with effective batch 256+ on a single GPU.
|
|
55
|
+
|
|
56
|
+
## Distillation losses
|
|
57
|
+
|
|
58
|
+
> **`activation_fn=nn.Identity()` is mandatory** for all distillation, listwise, and pairwise losses below. Only `BinaryCrossEntropyLoss` and `CrossEntropyLoss` tolerate the default `Sigmoid`. The loss sees raw logits during training, but the model's `activation_fn` is applied at evaluation via `predict()`. The default `Sigmoid` (with `num_labels=1`) saturates raw logits >5 to ~1.0 inside `predict()`, silently collapsing eval ranking (training loss looks healthy while nDCG crashes from ~0.59 to ~0.14). Construct as `CrossEncoder("...", num_labels=1, activation_fn=torch.nn.Identity())`. See `troubleshooting.md` ("CrossEncoder eval nDCG crashes after distillation / listwise / pairwise training") for the failure-mode walkthrough.
|
|
59
|
+
|
|
60
|
+
### `MSELoss` (cross-encoder)
|
|
61
|
+
|
|
62
|
+
Regress the student's output score to the teacher's score. Construct the model with `activation_fn=nn.Identity()` (see callout above).
|
|
63
|
+
|
|
64
|
+
- **Data**: `(query, passage, teacher_score)`.
|
|
65
|
+
- The teacher is typically a larger/stronger cross-encoder. Precompute its scores once, store as the label.
|
|
66
|
+
|
|
67
|
+
### `MarginMSELoss` (cross-encoder)
|
|
68
|
+
|
|
69
|
+
Regress the **difference** between positive and negative scores against the teacher's margin. Typically gives better distillation than plain MSE.
|
|
70
|
+
|
|
71
|
+
- **Data**: `(query, positive, negative, score_diff)` where `score_diff = teacher_score(query, positive) - teacher_score(query, negative)`.
|
|
72
|
+
- Popular recipe for MS MARCO-style distillation.
|
|
73
|
+
|
|
74
|
+
## Listwise losses
|
|
75
|
+
|
|
76
|
+
All listwise losses expect the dataset to have per-query **lists** of candidate passages and their scores, typically via a collator that groups rows by query.
|
|
77
|
+
|
|
78
|
+
> Listwise and pairwise losses below also require `activation_fn=nn.Identity()` (see the Distillation-section callout above).
|
|
79
|
+
|
|
80
|
+
### `LambdaLoss`
|
|
81
|
+
|
|
82
|
+
The state-of-the-art listwise ranking loss. Optimizes a surrogate of nDCG via weighted pairwise comparisons.
|
|
83
|
+
|
|
84
|
+
**Data shape**: `(query, [doc1...docN], [score1...scoreN])` per row. One query, a list of candidate documents, and a parallel list of relevance scores. Use `mine_hard_negatives(..., output_format="labeled-list", ...)` to build this from `(query, positive)` pairs. For ID-only datasets with separate text splits (e.g. `lightonai/ms-marco-en-bge`), `sentence_transformers.util.resolve_ids(..., output_format="lists")` produces this nested shape directly.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
import torch.nn as nn
|
|
88
|
+
from sentence_transformers.cross_encoder.losses import LambdaLoss, NDCGLoss2PPScheme
|
|
89
|
+
|
|
90
|
+
model = CrossEncoder("...", num_labels=1, activation_fn=nn.Identity())
|
|
91
|
+
loss = LambdaLoss(model, weighting_scheme=NDCGLoss2PPScheme())
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- Strong default when you have multiple candidates per query and graded relevance.
|
|
95
|
+
- `weighting_scheme`: `NDCGLoss2PPScheme` (default), `NDCGLoss2Scheme`, `LambdaRankScheme`. The `NDCGLoss2PPScheme` default was shown to reach the strongest performance in the original LambdaLoss paper.
|
|
96
|
+
|
|
97
|
+
#### LambdaLoss-specific operational notes
|
|
98
|
+
|
|
99
|
+
- **OOM recovery order**: drop `mini_batch_size` first (chunking inside the loss preserves the K-list semantic), then `per_device_train_batch_size` paired with `gradient_accumulation_steps`, then reduce K (the per-query candidate-list length) only as a last resort. Lowering K changes the experiment. The others don't.
|
|
100
|
+
- **Tiny loss at large K is expected.** With `NDCGLoss2PPScheme`, the loss normalizes by the discount-weighted pair count. At K=128 the loss can scale to ~`1e-4` numerically. That's not "training broken". Read `eval_NanoBEIR_R100_mean_ndcg@10` (or your equivalent) instead of the training loss to judge progress.
|
|
101
|
+
- For very large K (>=128), the O(K²) weight buffer per query is materialized outside of the forward chunking, so even small `mini_batch_size` may not be enough. Consider scoring strategy: top-K hard negatives often beat random K.
|
|
102
|
+
|
|
103
|
+
### `ListNetLoss`
|
|
104
|
+
|
|
105
|
+
Treats the ranking as a probability distribution (via softmax) and minimizes cross-entropy against the teacher distribution.
|
|
106
|
+
|
|
107
|
+
### `ListMLELoss`
|
|
108
|
+
|
|
109
|
+
Maximum-likelihood estimation over permutations. Simpler than LambdaLoss, decent default.
|
|
110
|
+
|
|
111
|
+
### `PListMLELoss`
|
|
112
|
+
|
|
113
|
+
Position-aware ListMLE. Weights higher-ranked items more heavily. Often outperforms plain ListMLE on top-k metrics.
|
|
114
|
+
|
|
115
|
+
### `RankNetLoss`
|
|
116
|
+
|
|
117
|
+
Pairwise classification: for each pair of candidates, predict which is ranked higher via cross-entropy.
|
|
118
|
+
|
|
119
|
+
- Simpler and faster than LambdaLoss.
|
|
120
|
+
- Scales quadratically with list length. Not great for long candidate lists (>20).
|
|
121
|
+
|
|
122
|
+
### `ADRMSELoss`
|
|
123
|
+
|
|
124
|
+
Alternative listwise formulation (Approx Discounted Rank MSE) from the Rank-DistiLLM paper. Same data shape as `LambdaLoss`. In practice LambdaLoss is the stronger default. `RankNetLoss` was reported as marginally more effective (~0.002 nDCG@10) than ADRMSELoss on the paper's LLM-distillation setup, and LambdaLoss generally beats both.
|
|
125
|
+
|
|
126
|
+
Hard-negative mining is essential for any contrastive reranker (random negatives teach nothing). See `dataset_formats.md` (Hard-negative mining section) and `../scripts/mine_hard_negatives.py`.
|
|
127
|
+
|
|
128
|
+
## Gotchas
|
|
129
|
+
|
|
130
|
+
- **`BinaryCrossEntropyLoss` without `pos_weight`** when you have 5+ hard negatives per positive: the loss under-weights the positive signal. Set `pos_weight=num_hard_negatives`.
|
|
131
|
+
- **`CachedMultipleNegativesRankingLoss` + `gradient_checkpointing=True`**: crash. Pick one.
|
|
132
|
+
- **Listwise losses with wildly different list lengths per query**: some losses don't handle ragged lists well. Pad or truncate to a fixed length.
|
|
133
|
+
- **`MarginMSELoss` without precomputed teacher score diffs**: this loss needs the `score_diff` label column populated from a teacher pass. It does not compute the teacher internally.
|
|
134
|
+
- **Training a cross-encoder with `num_labels=1` then using `CrossEntropyLoss`**: mismatch. BCE is for num_labels=1, CE is for num_labels>=2.
|
|
135
|
+
- **Default `Sigmoid` activation under any non-BCE loss**: silently destroys eval ranking. Pass `activation_fn=torch.nn.Identity()` to `CrossEncoder(...)` for distillation, listwise, and pairwise losses (everything except BCE/CE). See the callouts in the Distillation and Listwise sections.
|
|
136
|
+
- **Custom CE head writing to the wrong feature key**: a custom scoring head must populate `features["scores"]` (not `features["sentence_embedding"]`). Otherwise `CrossEncoder.predict()` raises `KeyError: 'scores'` at inference time, even though training succeeds.
|
|
137
|
+
- **Loading a CE with a custom-class head fails from a different script**: if you defined a `class ClassifierHead(nn.Module)` inline in `train.py` and saved the model, `modules.json` records `__main__.ClassifierHead`. Loading via `CrossEncoder("path")` from any other entry point raises `ImportError: Module '__main__' does not define a 'ClassifierHead' attribute`. Either move the class into an importable file (`my_pkg/heads.py`), build the same shape from stock ST modules (`Dense + LayerNorm + Dense`), or document that the model is only loadable from the same script.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Multi-Vector-Encoder Losses (ColBERT / late-interaction)
|
|
2
|
+
|
|
3
|
+
All losses live in `sentence_transformers.multi_vector_encoder.losses`.
|
|
4
|
+
|
|
5
|
+
Multi-vector models emit **one embedding per token** and score `(query, document)` via MaxSim (for each query token, take the max similarity to any document token, then sum across query tokens). This is fundamentally different from single-vector cosine, which changes what "temperature" means: MaxSim is an unbounded sum over query-token similarities, so for it a scale near 1.0 makes sense. **The default `scale=1.0` (temperature=1.0) is correct for unnormalized MaxSim: do not copy `scale=20.0` from bi-encoder MNRL.** With MeanMaxSim scoring (`similarity_fct=mean_colbert_scores`, and set `model.similarity_fn_name = "meanmaxsim"` so evaluation matches), each score is divided by its query's token count, so a scale of roughly the average length is a reasonable start, although some works use larger scales.
|
|
6
|
+
|
|
7
|
+
## Top-line decision table
|
|
8
|
+
|
|
9
|
+
| You have | Use |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `(anchor, positive)` or `(anchor, positive, negative)` triplets | `MultiVectorMultipleNegativesRankingLoss` |
|
|
12
|
+
| Same, want effective batch size of 128+ | `CachedMultiVectorMultipleNegativesRankingLoss` |
|
|
13
|
+
| Cross-encoder teacher scores, `(query, positive, negative, score_diff)` | `MultiVectorMarginMSELoss` |
|
|
14
|
+
| Listwise distillation `(query, [doc_1..doc_N], scores)` | `MultiVectorDistillKLDivLoss` |
|
|
15
|
+
|
|
16
|
+
Hard-negative mining is essential for competitive results, because random in-batch negatives leave a lot on the table for late-interaction models. See `dataset_formats.md` (Hard-negative mining section) and `../scripts/mine_hard_negatives.py`.
|
|
17
|
+
|
|
18
|
+
## Contrastive losses
|
|
19
|
+
|
|
20
|
+
### `MultiVectorMultipleNegativesRankingLoss`
|
|
21
|
+
|
|
22
|
+
The default late-interaction contrastive loss. In-batch positives plus explicit hard negatives, scored with MaxSim (or XTR).
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from sentence_transformers.multi_vector_encoder.losses import MultiVectorMultipleNegativesRankingLoss
|
|
26
|
+
|
|
27
|
+
loss = MultiVectorMultipleNegativesRankingLoss(model=model) # scale=1.0 (temperature=1.0) is the correct default
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- **Data**: `(anchor, positive)` or `(anchor, positive, negative_1, ..., negative_n)`. The collator stamps each column's task (column 0 becomes query, others become document). Pass `task=...` on a column to override.
|
|
31
|
+
- Set `batch_sampler=BatchSamplers.NO_DUPLICATES` on training args (same reason as bi-encoder MNRL).
|
|
32
|
+
- `similarity_fct=colbert_scores` by default. Pass `XTRScores(top_k=...)` for the sparser XTR-style scoring (from `sentence_transformers.multi_vector_encoder.scoring`). XTR applies to training only: evaluation always scores with MaxSim (see Gotchas).
|
|
33
|
+
- `scale=1.0` (temperature=1.0) matches PyLate and is correct for unnormalized MaxSim. **Do NOT copy `scale=20.0` from bi-encoder MNRL.** With MeanMaxSim (`similarity_fct=mean_colbert_scores`), raise the scale to roughly the average query length instead, which is the same objective at the same strength.
|
|
34
|
+
|
|
35
|
+
### `CachedMultiVectorMultipleNegativesRankingLoss`
|
|
36
|
+
|
|
37
|
+
GradCache variant: chunked embedding forward, cached gradients, and a second re-embedding pass. Decouples per-device batch size from effective in-batch negatives.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
loss = CachedMultiVectorMultipleNegativesRankingLoss(
|
|
41
|
+
model=model,
|
|
42
|
+
mini_batch_size=8, # or use mini_batch_num_tokens=... for token-budgeted packing
|
|
43
|
+
score_mini_batch_size=4, # optional, smaller trims the transient (Q, Q*N, q_tok, d_tok) buffer
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- **Incompatible with `gradient_checkpointing=True`** (same as every `Cached*` loss).
|
|
48
|
+
- `mini_batch_num_tokens=N` packs sequences until N real tokens per mini-batch instead of a fixed `mini_batch_size`. Big win on variable-length data with flash-attention / input flattening.
|
|
49
|
+
- `score_mini_batch_size` chunks the SCORING phase (which builds `(Q, Q*N, q_tokens, d_tokens)` intermediates) independently from the embedding phase. Drop it first when hitting OOM in the loss stage.
|
|
50
|
+
- `chunk_elements` is the second lever on that same phase, and it cuts the other axis: `score_mini_batch_size` chunks queries, `chunk_elements` chunks documents inside each MaxSim call. Pass it through the scorer, e.g. `similarity_fct=partial(colbert_scores, chunk_elements=1_000_000)`. Scores and gradients are unchanged (it is a pure memory knob), and it composes with `score_mini_batch_size`.
|
|
51
|
+
- `gather_across_devices=True` gathers document embeddings across DDP ranks. Enables cross-rank in-batch negatives.
|
|
52
|
+
|
|
53
|
+
## Distillation losses
|
|
54
|
+
|
|
55
|
+
Distillation is where multi-vector models learn most efficiently: cross-encoder teachers (e.g. `gte-modernbert-base`) score `(query, doc)` pairs offline, and the student MaxSim model regresses to that signal.
|
|
56
|
+
|
|
57
|
+
For the standard MS MARCO KD format (LightOn's `ms-marco-en-bge` and similar: `(query_id, document_ids, scores)` with separate `queries` / `documents` splits), you can use `sentence_transformers.util.resolve_ids` to join the IDs against the text splits at load time. It's a factory that returns a batched transform: pass a mapping from each input ID column to its lookup dataset, e.g. `dataset.set_transform(resolve_ids({"query_id": queries, "document_ids": documents}, max_list_length=32))` (lazy, no caching) or via `dataset.map(..., batched=True, remove_columns=["query_id", "document_ids"])` (eager, cached: `map` keeps input columns unless told to drop them, so pass the ID columns to `remove_columns`), yielding `(query, document_1, ..., document_32, scores)` rows ready for `MultiVectorDistillKLDivLoss`. The same mapping shape covers triplets with IDs (`{"query_id": queries, "positive_id": documents, "negative_id": documents}`) and ID-only contrastive datasets without a `scores` column.
|
|
58
|
+
|
|
59
|
+
### `MultiVectorMarginMSELoss`
|
|
60
|
+
|
|
61
|
+
Regress the **margin** between positive and negative MaxSim scores against the teacher's margin.
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
loss = MultiVectorMarginMSELoss(model=model)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- **Data**: `(query, positive, negative, score_diff)` where `score_diff = teacher_score(query, positive) - teacher_score(query, negative)`. Raw teacher scores `[score(q, pos), score(q, neg_1), ...]` also work, converted to margins internally.
|
|
68
|
+
- Popular recipe from PyLate / colpali-engine.
|
|
69
|
+
- Teacher scores are precomputed once, stored as the label column. The loss does not run the teacher inline.
|
|
70
|
+
- Same `similarity_fct` convention as the other losses, but pairwise-shaped: defaults to `colbert_scores_pairwise`, or pass `xtr_scores_pairwise` for XTR.
|
|
71
|
+
|
|
72
|
+
### `MultiVectorDistillKLDivLoss`
|
|
73
|
+
|
|
74
|
+
Listwise KL-div: student's softmax distribution over N candidates should match the teacher's.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
loss = MultiVectorDistillKLDivLoss(model=model)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- **Data**: `(query, document_1, ..., document_N, scores)` where `scores` is a list of N teacher scores per row. One column per candidate document (the standard positional multi-column convention), and the label column must use a recognized name (`label`, `labels`, `score`, `scores`). `resolve_ids` expands a stored ID list into the numbered columns.
|
|
81
|
+
- Stronger training signal than `MarginMSE` when you have full `N`-way teacher scores (not just positive/negative margins).
|
|
82
|
+
- `similarity_fct` defaults to `colbert_kd_scores`, the listwise KD variant, not the `colbert_scores` used by the MNRL family. `XTRKDScores` is the XTR counterpart.
|
|
83
|
+
- `temperature` softens both distributions before the softmax, and can be overridden per side with `student_temperature` / `teacher_temperature`. Set `teacher_temperature` from the spread of your teacher's scores rather than from a value copied out of a paper: a float32 softmax underflows to exact zeros once a row's spread divided by the temperature exceeds about 100, and every candidate that underflows drops out of the KL, which is the ranking information you are distilling. Sharpening `student_temperature` far below the student's own score spread collapses that side too, and once both are one-hot the loss and its gradient are exactly zero. **Start at 1.0 / 1.0 and only move a side you have a measured reason to move.**
|
|
84
|
+
- The loss is scaled by the student temperature squared, which keeps gradient magnitudes comparable only for a shared temperature at or above 1.0 (the regime Hinton et al. cover). Below that the factor shrinks the loss instead, by 1e-6 at `student_temperature=0.001`: when combining KD with a contrastive loss, scale the KD weight back up accordingly.
|
|
85
|
+
- **OOM**: drop `per_device_train_batch_size` first and raise `gradient_accumulation_steps` to hold the effective batch. Only reduce `N` (candidate-list length) as a last resort, since lowering N changes the experiment.
|
|
86
|
+
|
|
87
|
+
## Data-shape gotchas
|
|
88
|
+
|
|
89
|
+
- **Column 0 is always the query.** Losses call `self.model(sf, task="query" if idx==0 else "document")`. Use the collator's `router_mapping` to override if you need a non-standard column layout.
|
|
90
|
+
- **Cross-column varlen `T`** is handled: the batch's positive and negative columns can have different token counts (Qwen2-VL family etc.). `stack_padded_token_embeddings` pads to the per-batch max before MaxSim.
|
|
91
|
+
- **Mask flow**: MVE reads the SCORING mask from the model OUTPUT dict (`MultiVectorMask` rewrites the input mask). Custom loss code that reads `sentence_features[i]["attention_mask"]` directly instead of `outputs[i]["attention_mask"]` will silently score against skiplisted tokens.
|
|
92
|
+
|
|
93
|
+
## Gotchas
|
|
94
|
+
|
|
95
|
+
- **`scale=20.0` copied from bi-encoder MNRL**: misscaled for the unnormalized MaxSim sum. Keep `scale=1.0` there. Only length-normalized MeanMaxSim wants a larger scale, roughly the average query length.
|
|
96
|
+
- **Missing `Normalize` at the token level in the pipeline**: `colbert_scores` assumes L2-normalized token embeddings. If your custom pipeline drops the token-level `Normalize`, either add one or pass `normalize_embeddings=True` semantics via a wrapper.
|
|
97
|
+
- **`CachedMultiVectorMultipleNegativesRankingLoss` + `gradient_checkpointing=True`**: crash. Pick one.
|
|
98
|
+
- **`MultiVectorMarginMSELoss` without precomputed `score_diff`**: label column must be populated from a teacher pass ahead of training. The loss does not compute the teacher inline.
|
|
99
|
+
- **Expecting XTR scoring at eval**: `XTRScores` is a train-only `similarity_fct`. XTR takes its top-k across the whole candidate set, so a `(query, document)` pair has no standalone score, which means it cannot be the model's `similarity_fn_name` and the evaluators reject it outright. Evaluation and inference score with MaxSim, also for XTR-trained models. That is by design, not a mismatch to fix. To score a fixed candidate set ad hoc, call `xtr_scores` directly.
|
|
100
|
+
- **Distillation with a weak teacher**: multi-vector students easily match a small-model teacher and then plateau. Use a strong cross-encoder (e.g. `gte-modernbert-base`, `mxbai-rerank-large-v2`) for the teacher pass.
|