@synsci/cli-darwin-x64 1.1.49
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/bin/skills/accelerate/SKILL.md +332 -0
- package/bin/skills/accelerate/references/custom-plugins.md +453 -0
- package/bin/skills/accelerate/references/megatron-integration.md +489 -0
- package/bin/skills/accelerate/references/performance.md +525 -0
- package/bin/skills/audiocraft/SKILL.md +564 -0
- package/bin/skills/audiocraft/references/advanced-usage.md +666 -0
- package/bin/skills/audiocraft/references/troubleshooting.md +504 -0
- package/bin/skills/autogpt/SKILL.md +403 -0
- package/bin/skills/autogpt/references/advanced-usage.md +535 -0
- package/bin/skills/autogpt/references/troubleshooting.md +420 -0
- package/bin/skills/awq/SKILL.md +310 -0
- package/bin/skills/awq/references/advanced-usage.md +324 -0
- package/bin/skills/awq/references/troubleshooting.md +344 -0
- package/bin/skills/axolotl/SKILL.md +158 -0
- package/bin/skills/axolotl/references/api.md +5548 -0
- package/bin/skills/axolotl/references/dataset-formats.md +1029 -0
- package/bin/skills/axolotl/references/index.md +15 -0
- package/bin/skills/axolotl/references/other.md +3563 -0
- package/bin/skills/bigcode-evaluation-harness/SKILL.md +405 -0
- package/bin/skills/bigcode-evaluation-harness/references/benchmarks.md +393 -0
- package/bin/skills/bigcode-evaluation-harness/references/custom-tasks.md +424 -0
- package/bin/skills/bigcode-evaluation-harness/references/issues.md +394 -0
- package/bin/skills/bitsandbytes/SKILL.md +411 -0
- package/bin/skills/bitsandbytes/references/memory-optimization.md +521 -0
- package/bin/skills/bitsandbytes/references/qlora-training.md +521 -0
- package/bin/skills/bitsandbytes/references/quantization-formats.md +447 -0
- package/bin/skills/blip-2/SKILL.md +564 -0
- package/bin/skills/blip-2/references/advanced-usage.md +680 -0
- package/bin/skills/blip-2/references/troubleshooting.md +526 -0
- package/bin/skills/chroma/SKILL.md +406 -0
- package/bin/skills/chroma/references/integration.md +38 -0
- package/bin/skills/clip/SKILL.md +253 -0
- package/bin/skills/clip/references/applications.md +207 -0
- package/bin/skills/constitutional-ai/SKILL.md +290 -0
- package/bin/skills/crewai/SKILL.md +498 -0
- package/bin/skills/crewai/references/flows.md +438 -0
- package/bin/skills/crewai/references/tools.md +429 -0
- package/bin/skills/crewai/references/troubleshooting.md +480 -0
- package/bin/skills/deepspeed/SKILL.md +141 -0
- package/bin/skills/deepspeed/references/08.md +17 -0
- package/bin/skills/deepspeed/references/09.md +173 -0
- package/bin/skills/deepspeed/references/2020.md +378 -0
- package/bin/skills/deepspeed/references/2023.md +279 -0
- package/bin/skills/deepspeed/references/assets.md +179 -0
- package/bin/skills/deepspeed/references/index.md +35 -0
- package/bin/skills/deepspeed/references/mii.md +118 -0
- package/bin/skills/deepspeed/references/other.md +1191 -0
- package/bin/skills/deepspeed/references/tutorials.md +6554 -0
- package/bin/skills/dspy/SKILL.md +590 -0
- package/bin/skills/dspy/references/examples.md +663 -0
- package/bin/skills/dspy/references/modules.md +475 -0
- package/bin/skills/dspy/references/optimizers.md +566 -0
- package/bin/skills/faiss/SKILL.md +221 -0
- package/bin/skills/faiss/references/index_types.md +280 -0
- package/bin/skills/flash-attention/SKILL.md +367 -0
- package/bin/skills/flash-attention/references/benchmarks.md +215 -0
- package/bin/skills/flash-attention/references/transformers-integration.md +293 -0
- package/bin/skills/gguf/SKILL.md +427 -0
- package/bin/skills/gguf/references/advanced-usage.md +504 -0
- package/bin/skills/gguf/references/troubleshooting.md +442 -0
- package/bin/skills/gptq/SKILL.md +450 -0
- package/bin/skills/gptq/references/calibration.md +337 -0
- package/bin/skills/gptq/references/integration.md +129 -0
- package/bin/skills/gptq/references/troubleshooting.md +95 -0
- package/bin/skills/grpo-rl-training/README.md +97 -0
- package/bin/skills/grpo-rl-training/SKILL.md +572 -0
- package/bin/skills/grpo-rl-training/examples/reward_functions_library.py +393 -0
- package/bin/skills/grpo-rl-training/templates/basic_grpo_training.py +228 -0
- package/bin/skills/guidance/SKILL.md +572 -0
- package/bin/skills/guidance/references/backends.md +554 -0
- package/bin/skills/guidance/references/constraints.md +674 -0
- package/bin/skills/guidance/references/examples.md +767 -0
- package/bin/skills/hqq/SKILL.md +445 -0
- package/bin/skills/hqq/references/advanced-usage.md +528 -0
- package/bin/skills/hqq/references/troubleshooting.md +503 -0
- package/bin/skills/hugging-face-cli/SKILL.md +191 -0
- package/bin/skills/hugging-face-cli/references/commands.md +954 -0
- package/bin/skills/hugging-face-cli/references/examples.md +374 -0
- package/bin/skills/hugging-face-datasets/SKILL.md +547 -0
- package/bin/skills/hugging-face-datasets/examples/diverse_training_examples.json +239 -0
- package/bin/skills/hugging-face-datasets/examples/system_prompt_template.txt +196 -0
- package/bin/skills/hugging-face-datasets/examples/training_examples.json +176 -0
- package/bin/skills/hugging-face-datasets/scripts/dataset_manager.py +522 -0
- package/bin/skills/hugging-face-datasets/scripts/sql_manager.py +844 -0
- package/bin/skills/hugging-face-datasets/templates/chat.json +55 -0
- package/bin/skills/hugging-face-datasets/templates/classification.json +62 -0
- package/bin/skills/hugging-face-datasets/templates/completion.json +51 -0
- package/bin/skills/hugging-face-datasets/templates/custom.json +75 -0
- package/bin/skills/hugging-face-datasets/templates/qa.json +54 -0
- package/bin/skills/hugging-face-datasets/templates/tabular.json +81 -0
- package/bin/skills/hugging-face-evaluation/SKILL.md +656 -0
- package/bin/skills/hugging-face-evaluation/examples/USAGE_EXAMPLES.md +382 -0
- package/bin/skills/hugging-face-evaluation/examples/artificial_analysis_to_hub.py +141 -0
- package/bin/skills/hugging-face-evaluation/examples/example_readme_tables.md +135 -0
- package/bin/skills/hugging-face-evaluation/examples/metric_mapping.json +50 -0
- package/bin/skills/hugging-face-evaluation/requirements.txt +20 -0
- package/bin/skills/hugging-face-evaluation/scripts/evaluation_manager.py +1374 -0
- package/bin/skills/hugging-face-evaluation/scripts/inspect_eval_uv.py +104 -0
- package/bin/skills/hugging-face-evaluation/scripts/inspect_vllm_uv.py +317 -0
- package/bin/skills/hugging-face-evaluation/scripts/lighteval_vllm_uv.py +303 -0
- package/bin/skills/hugging-face-evaluation/scripts/run_eval_job.py +98 -0
- package/bin/skills/hugging-face-evaluation/scripts/run_vllm_eval_job.py +331 -0
- package/bin/skills/hugging-face-evaluation/scripts/test_extraction.py +206 -0
- package/bin/skills/hugging-face-jobs/SKILL.md +1041 -0
- package/bin/skills/hugging-face-jobs/index.html +216 -0
- package/bin/skills/hugging-face-jobs/references/hardware_guide.md +336 -0
- package/bin/skills/hugging-face-jobs/references/hub_saving.md +352 -0
- package/bin/skills/hugging-face-jobs/references/token_usage.md +546 -0
- package/bin/skills/hugging-face-jobs/references/troubleshooting.md +475 -0
- package/bin/skills/hugging-face-jobs/scripts/cot-self-instruct.py +718 -0
- package/bin/skills/hugging-face-jobs/scripts/finepdfs-stats.py +546 -0
- package/bin/skills/hugging-face-jobs/scripts/generate-responses.py +587 -0
- package/bin/skills/hugging-face-model-trainer/SKILL.md +711 -0
- package/bin/skills/hugging-face-model-trainer/references/gguf_conversion.md +296 -0
- package/bin/skills/hugging-face-model-trainer/references/hardware_guide.md +283 -0
- package/bin/skills/hugging-face-model-trainer/references/hub_saving.md +364 -0
- package/bin/skills/hugging-face-model-trainer/references/reliability_principles.md +371 -0
- package/bin/skills/hugging-face-model-trainer/references/trackio_guide.md +189 -0
- package/bin/skills/hugging-face-model-trainer/references/training_methods.md +150 -0
- package/bin/skills/hugging-face-model-trainer/references/training_patterns.md +203 -0
- package/bin/skills/hugging-face-model-trainer/references/troubleshooting.md +282 -0
- package/bin/skills/hugging-face-model-trainer/scripts/convert_to_gguf.py +424 -0
- package/bin/skills/hugging-face-model-trainer/scripts/dataset_inspector.py +417 -0
- package/bin/skills/hugging-face-model-trainer/scripts/estimate_cost.py +150 -0
- package/bin/skills/hugging-face-model-trainer/scripts/train_dpo_example.py +106 -0
- package/bin/skills/hugging-face-model-trainer/scripts/train_grpo_example.py +89 -0
- package/bin/skills/hugging-face-model-trainer/scripts/train_sft_example.py +122 -0
- package/bin/skills/hugging-face-paper-publisher/SKILL.md +627 -0
- package/bin/skills/hugging-face-paper-publisher/examples/example_usage.md +327 -0
- package/bin/skills/hugging-face-paper-publisher/references/quick_reference.md +216 -0
- package/bin/skills/hugging-face-paper-publisher/scripts/paper_manager.py +508 -0
- package/bin/skills/hugging-face-paper-publisher/templates/arxiv.md +299 -0
- package/bin/skills/hugging-face-paper-publisher/templates/ml-report.md +358 -0
- package/bin/skills/hugging-face-paper-publisher/templates/modern.md +319 -0
- package/bin/skills/hugging-face-paper-publisher/templates/standard.md +201 -0
- package/bin/skills/hugging-face-tool-builder/SKILL.md +115 -0
- package/bin/skills/hugging-face-tool-builder/references/baseline_hf_api.py +57 -0
- package/bin/skills/hugging-face-tool-builder/references/baseline_hf_api.sh +40 -0
- package/bin/skills/hugging-face-tool-builder/references/baseline_hf_api.tsx +57 -0
- package/bin/skills/hugging-face-tool-builder/references/find_models_by_paper.sh +230 -0
- package/bin/skills/hugging-face-tool-builder/references/hf_enrich_models.sh +96 -0
- package/bin/skills/hugging-face-tool-builder/references/hf_model_card_frontmatter.sh +188 -0
- package/bin/skills/hugging-face-tool-builder/references/hf_model_papers_auth.sh +171 -0
- package/bin/skills/hugging-face-trackio/SKILL.md +65 -0
- package/bin/skills/hugging-face-trackio/references/logging_metrics.md +206 -0
- package/bin/skills/hugging-face-trackio/references/retrieving_metrics.md +223 -0
- package/bin/skills/huggingface-tokenizers/SKILL.md +516 -0
- package/bin/skills/huggingface-tokenizers/references/algorithms.md +653 -0
- package/bin/skills/huggingface-tokenizers/references/integration.md +637 -0
- package/bin/skills/huggingface-tokenizers/references/pipeline.md +723 -0
- package/bin/skills/huggingface-tokenizers/references/training.md +565 -0
- package/bin/skills/instructor/SKILL.md +740 -0
- package/bin/skills/instructor/references/examples.md +107 -0
- package/bin/skills/instructor/references/providers.md +70 -0
- package/bin/skills/instructor/references/validation.md +606 -0
- package/bin/skills/knowledge-distillation/SKILL.md +458 -0
- package/bin/skills/knowledge-distillation/references/minillm.md +334 -0
- package/bin/skills/lambda-labs/SKILL.md +545 -0
- package/bin/skills/lambda-labs/references/advanced-usage.md +611 -0
- package/bin/skills/lambda-labs/references/troubleshooting.md +530 -0
- package/bin/skills/langchain/SKILL.md +480 -0
- package/bin/skills/langchain/references/agents.md +499 -0
- package/bin/skills/langchain/references/integration.md +562 -0
- package/bin/skills/langchain/references/rag.md +600 -0
- package/bin/skills/langsmith/SKILL.md +422 -0
- package/bin/skills/langsmith/references/advanced-usage.md +548 -0
- package/bin/skills/langsmith/references/troubleshooting.md +537 -0
- package/bin/skills/litgpt/SKILL.md +469 -0
- package/bin/skills/litgpt/references/custom-models.md +568 -0
- package/bin/skills/litgpt/references/distributed-training.md +451 -0
- package/bin/skills/litgpt/references/supported-models.md +336 -0
- package/bin/skills/litgpt/references/training-recipes.md +619 -0
- package/bin/skills/llama-cpp/SKILL.md +258 -0
- package/bin/skills/llama-cpp/references/optimization.md +89 -0
- package/bin/skills/llama-cpp/references/quantization.md +213 -0
- package/bin/skills/llama-cpp/references/server.md +125 -0
- package/bin/skills/llama-factory/SKILL.md +80 -0
- package/bin/skills/llama-factory/references/_images.md +23 -0
- package/bin/skills/llama-factory/references/advanced.md +1055 -0
- package/bin/skills/llama-factory/references/getting_started.md +349 -0
- package/bin/skills/llama-factory/references/index.md +19 -0
- package/bin/skills/llama-factory/references/other.md +31 -0
- package/bin/skills/llamaguard/SKILL.md +337 -0
- package/bin/skills/llamaindex/SKILL.md +569 -0
- package/bin/skills/llamaindex/references/agents.md +83 -0
- package/bin/skills/llamaindex/references/data_connectors.md +108 -0
- package/bin/skills/llamaindex/references/query_engines.md +406 -0
- package/bin/skills/llava/SKILL.md +304 -0
- package/bin/skills/llava/references/training.md +197 -0
- package/bin/skills/lm-evaluation-harness/SKILL.md +490 -0
- package/bin/skills/lm-evaluation-harness/references/api-evaluation.md +490 -0
- package/bin/skills/lm-evaluation-harness/references/benchmark-guide.md +488 -0
- package/bin/skills/lm-evaluation-harness/references/custom-tasks.md +602 -0
- package/bin/skills/lm-evaluation-harness/references/distributed-eval.md +519 -0
- package/bin/skills/long-context/SKILL.md +536 -0
- package/bin/skills/long-context/references/extension_methods.md +468 -0
- package/bin/skills/long-context/references/fine_tuning.md +611 -0
- package/bin/skills/long-context/references/rope.md +402 -0
- package/bin/skills/mamba/SKILL.md +260 -0
- package/bin/skills/mamba/references/architecture-details.md +206 -0
- package/bin/skills/mamba/references/benchmarks.md +255 -0
- package/bin/skills/mamba/references/training-guide.md +388 -0
- package/bin/skills/megatron-core/SKILL.md +366 -0
- package/bin/skills/megatron-core/references/benchmarks.md +249 -0
- package/bin/skills/megatron-core/references/parallelism-guide.md +404 -0
- package/bin/skills/megatron-core/references/production-examples.md +473 -0
- package/bin/skills/megatron-core/references/training-recipes.md +547 -0
- package/bin/skills/miles/SKILL.md +315 -0
- package/bin/skills/miles/references/api-reference.md +141 -0
- package/bin/skills/miles/references/troubleshooting.md +352 -0
- package/bin/skills/mlflow/SKILL.md +704 -0
- package/bin/skills/mlflow/references/deployment.md +744 -0
- package/bin/skills/mlflow/references/model-registry.md +770 -0
- package/bin/skills/mlflow/references/tracking.md +680 -0
- package/bin/skills/modal/SKILL.md +341 -0
- package/bin/skills/modal/references/advanced-usage.md +503 -0
- package/bin/skills/modal/references/troubleshooting.md +494 -0
- package/bin/skills/model-merging/SKILL.md +539 -0
- package/bin/skills/model-merging/references/evaluation.md +462 -0
- package/bin/skills/model-merging/references/examples.md +428 -0
- package/bin/skills/model-merging/references/methods.md +352 -0
- package/bin/skills/model-pruning/SKILL.md +495 -0
- package/bin/skills/model-pruning/references/wanda.md +347 -0
- package/bin/skills/moe-training/SKILL.md +526 -0
- package/bin/skills/moe-training/references/architectures.md +432 -0
- package/bin/skills/moe-training/references/inference.md +348 -0
- package/bin/skills/moe-training/references/training.md +425 -0
- package/bin/skills/nanogpt/SKILL.md +290 -0
- package/bin/skills/nanogpt/references/architecture.md +382 -0
- package/bin/skills/nanogpt/references/data.md +476 -0
- package/bin/skills/nanogpt/references/training.md +564 -0
- package/bin/skills/nemo-curator/SKILL.md +383 -0
- package/bin/skills/nemo-curator/references/deduplication.md +87 -0
- package/bin/skills/nemo-curator/references/filtering.md +102 -0
- package/bin/skills/nemo-evaluator/SKILL.md +494 -0
- package/bin/skills/nemo-evaluator/references/adapter-system.md +340 -0
- package/bin/skills/nemo-evaluator/references/configuration.md +447 -0
- package/bin/skills/nemo-evaluator/references/custom-benchmarks.md +315 -0
- package/bin/skills/nemo-evaluator/references/execution-backends.md +361 -0
- package/bin/skills/nemo-guardrails/SKILL.md +297 -0
- package/bin/skills/nnsight/SKILL.md +436 -0
- package/bin/skills/nnsight/references/README.md +78 -0
- package/bin/skills/nnsight/references/api.md +344 -0
- package/bin/skills/nnsight/references/tutorials.md +300 -0
- package/bin/skills/openrlhf/SKILL.md +249 -0
- package/bin/skills/openrlhf/references/algorithm-comparison.md +404 -0
- package/bin/skills/openrlhf/references/custom-rewards.md +530 -0
- package/bin/skills/openrlhf/references/hybrid-engine.md +287 -0
- package/bin/skills/openrlhf/references/multi-node-training.md +454 -0
- package/bin/skills/outlines/SKILL.md +652 -0
- package/bin/skills/outlines/references/backends.md +615 -0
- package/bin/skills/outlines/references/examples.md +773 -0
- package/bin/skills/outlines/references/json_generation.md +652 -0
- package/bin/skills/peft/SKILL.md +431 -0
- package/bin/skills/peft/references/advanced-usage.md +514 -0
- package/bin/skills/peft/references/troubleshooting.md +480 -0
- package/bin/skills/phoenix/SKILL.md +475 -0
- package/bin/skills/phoenix/references/advanced-usage.md +619 -0
- package/bin/skills/phoenix/references/troubleshooting.md +538 -0
- package/bin/skills/pinecone/SKILL.md +358 -0
- package/bin/skills/pinecone/references/deployment.md +181 -0
- package/bin/skills/pytorch-fsdp/SKILL.md +126 -0
- package/bin/skills/pytorch-fsdp/references/index.md +7 -0
- package/bin/skills/pytorch-fsdp/references/other.md +4249 -0
- package/bin/skills/pytorch-lightning/SKILL.md +346 -0
- package/bin/skills/pytorch-lightning/references/callbacks.md +436 -0
- package/bin/skills/pytorch-lightning/references/distributed.md +490 -0
- package/bin/skills/pytorch-lightning/references/hyperparameter-tuning.md +556 -0
- package/bin/skills/pyvene/SKILL.md +473 -0
- package/bin/skills/pyvene/references/README.md +73 -0
- package/bin/skills/pyvene/references/api.md +383 -0
- package/bin/skills/pyvene/references/tutorials.md +376 -0
- package/bin/skills/qdrant/SKILL.md +493 -0
- package/bin/skills/qdrant/references/advanced-usage.md +648 -0
- package/bin/skills/qdrant/references/troubleshooting.md +631 -0
- package/bin/skills/ray-data/SKILL.md +326 -0
- package/bin/skills/ray-data/references/integration.md +82 -0
- package/bin/skills/ray-data/references/transformations.md +83 -0
- package/bin/skills/ray-train/SKILL.md +406 -0
- package/bin/skills/ray-train/references/multi-node.md +628 -0
- package/bin/skills/rwkv/SKILL.md +260 -0
- package/bin/skills/rwkv/references/architecture-details.md +344 -0
- package/bin/skills/rwkv/references/rwkv7.md +386 -0
- package/bin/skills/rwkv/references/state-management.md +369 -0
- package/bin/skills/saelens/SKILL.md +386 -0
- package/bin/skills/saelens/references/README.md +70 -0
- package/bin/skills/saelens/references/api.md +333 -0
- package/bin/skills/saelens/references/tutorials.md +318 -0
- package/bin/skills/segment-anything/SKILL.md +500 -0
- package/bin/skills/segment-anything/references/advanced-usage.md +589 -0
- package/bin/skills/segment-anything/references/troubleshooting.md +484 -0
- package/bin/skills/sentence-transformers/SKILL.md +255 -0
- package/bin/skills/sentence-transformers/references/models.md +123 -0
- package/bin/skills/sentencepiece/SKILL.md +235 -0
- package/bin/skills/sentencepiece/references/algorithms.md +200 -0
- package/bin/skills/sentencepiece/references/training.md +304 -0
- package/bin/skills/sglang/SKILL.md +442 -0
- package/bin/skills/sglang/references/deployment.md +490 -0
- package/bin/skills/sglang/references/radix-attention.md +413 -0
- package/bin/skills/sglang/references/structured-generation.md +541 -0
- package/bin/skills/simpo/SKILL.md +219 -0
- package/bin/skills/simpo/references/datasets.md +478 -0
- package/bin/skills/simpo/references/hyperparameters.md +452 -0
- package/bin/skills/simpo/references/loss-functions.md +350 -0
- package/bin/skills/skypilot/SKILL.md +509 -0
- package/bin/skills/skypilot/references/advanced-usage.md +491 -0
- package/bin/skills/skypilot/references/troubleshooting.md +570 -0
- package/bin/skills/slime/SKILL.md +464 -0
- package/bin/skills/slime/references/api-reference.md +392 -0
- package/bin/skills/slime/references/troubleshooting.md +386 -0
- package/bin/skills/speculative-decoding/SKILL.md +467 -0
- package/bin/skills/speculative-decoding/references/lookahead.md +309 -0
- package/bin/skills/speculative-decoding/references/medusa.md +350 -0
- package/bin/skills/stable-diffusion/SKILL.md +519 -0
- package/bin/skills/stable-diffusion/references/advanced-usage.md +716 -0
- package/bin/skills/stable-diffusion/references/troubleshooting.md +555 -0
- package/bin/skills/tensorboard/SKILL.md +629 -0
- package/bin/skills/tensorboard/references/integrations.md +638 -0
- package/bin/skills/tensorboard/references/profiling.md +545 -0
- package/bin/skills/tensorboard/references/visualization.md +620 -0
- package/bin/skills/tensorrt-llm/SKILL.md +187 -0
- package/bin/skills/tensorrt-llm/references/multi-gpu.md +298 -0
- package/bin/skills/tensorrt-llm/references/optimization.md +242 -0
- package/bin/skills/tensorrt-llm/references/serving.md +470 -0
- package/bin/skills/tinker/SKILL.md +362 -0
- package/bin/skills/tinker/references/api-reference.md +168 -0
- package/bin/skills/tinker/references/getting-started.md +157 -0
- package/bin/skills/tinker/references/loss-functions.md +163 -0
- package/bin/skills/tinker/references/models-and-lora.md +139 -0
- package/bin/skills/tinker/references/recipes.md +280 -0
- package/bin/skills/tinker/references/reinforcement-learning.md +212 -0
- package/bin/skills/tinker/references/rendering.md +243 -0
- package/bin/skills/tinker/references/supervised-learning.md +232 -0
- package/bin/skills/tinker-training-cost/SKILL.md +187 -0
- package/bin/skills/tinker-training-cost/scripts/calculate_cost.py +123 -0
- package/bin/skills/torchforge/SKILL.md +433 -0
- package/bin/skills/torchforge/references/api-reference.md +327 -0
- package/bin/skills/torchforge/references/troubleshooting.md +409 -0
- package/bin/skills/torchtitan/SKILL.md +358 -0
- package/bin/skills/torchtitan/references/checkpoint.md +181 -0
- package/bin/skills/torchtitan/references/custom-models.md +258 -0
- package/bin/skills/torchtitan/references/float8.md +133 -0
- package/bin/skills/torchtitan/references/fsdp.md +126 -0
- package/bin/skills/transformer-lens/SKILL.md +346 -0
- package/bin/skills/transformer-lens/references/README.md +54 -0
- package/bin/skills/transformer-lens/references/api.md +362 -0
- package/bin/skills/transformer-lens/references/tutorials.md +339 -0
- package/bin/skills/trl-fine-tuning/SKILL.md +455 -0
- package/bin/skills/trl-fine-tuning/references/dpo-variants.md +227 -0
- package/bin/skills/trl-fine-tuning/references/online-rl.md +82 -0
- package/bin/skills/trl-fine-tuning/references/reward-modeling.md +122 -0
- package/bin/skills/trl-fine-tuning/references/sft-training.md +168 -0
- package/bin/skills/unsloth/SKILL.md +80 -0
- package/bin/skills/unsloth/references/index.md +7 -0
- package/bin/skills/unsloth/references/llms-full.md +16799 -0
- package/bin/skills/unsloth/references/llms-txt.md +12044 -0
- package/bin/skills/unsloth/references/llms.md +82 -0
- package/bin/skills/verl/SKILL.md +391 -0
- package/bin/skills/verl/references/api-reference.md +301 -0
- package/bin/skills/verl/references/troubleshooting.md +391 -0
- package/bin/skills/vllm/SKILL.md +364 -0
- package/bin/skills/vllm/references/optimization.md +226 -0
- package/bin/skills/vllm/references/quantization.md +284 -0
- package/bin/skills/vllm/references/server-deployment.md +255 -0
- package/bin/skills/vllm/references/troubleshooting.md +447 -0
- package/bin/skills/weights-and-biases/SKILL.md +590 -0
- package/bin/skills/weights-and-biases/references/artifacts.md +584 -0
- package/bin/skills/weights-and-biases/references/integrations.md +700 -0
- package/bin/skills/weights-and-biases/references/sweeps.md +847 -0
- package/bin/skills/whisper/SKILL.md +317 -0
- package/bin/skills/whisper/references/languages.md +189 -0
- package/bin/synsc +0 -0
- package/package.json +10 -0
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
# DSPy Real-World Examples
|
|
2
|
+
|
|
3
|
+
Practical examples of building production systems with DSPy.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
- RAG Systems
|
|
7
|
+
- Agent Systems
|
|
8
|
+
- Classification
|
|
9
|
+
- Data Processing
|
|
10
|
+
- Multi-Stage Pipelines
|
|
11
|
+
|
|
12
|
+
## RAG Systems
|
|
13
|
+
|
|
14
|
+
### Basic RAG
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
import dspy
|
|
18
|
+
|
|
19
|
+
class BasicRAG(dspy.Module):
|
|
20
|
+
def __init__(self, num_passages=3):
|
|
21
|
+
super().__init__()
|
|
22
|
+
self.retrieve = dspy.Retrieve(k=num_passages)
|
|
23
|
+
self.generate = dspy.ChainOfThought("context, question -> answer")
|
|
24
|
+
|
|
25
|
+
def forward(self, question):
|
|
26
|
+
passages = self.retrieve(question).passages
|
|
27
|
+
context = "\n\n".join(passages)
|
|
28
|
+
return self.generate(context=context, question=question)
|
|
29
|
+
|
|
30
|
+
# Configure retriever (example with Chroma)
|
|
31
|
+
from dspy.retrieve.chromadb_rm import ChromadbRM
|
|
32
|
+
|
|
33
|
+
retriever = ChromadbRM(
|
|
34
|
+
collection_name="my_docs",
|
|
35
|
+
persist_directory="./chroma_db",
|
|
36
|
+
k=3
|
|
37
|
+
)
|
|
38
|
+
dspy.settings.configure(rm=retriever)
|
|
39
|
+
|
|
40
|
+
# Use RAG
|
|
41
|
+
rag = BasicRAG()
|
|
42
|
+
result = rag(question="What is DSPy?")
|
|
43
|
+
print(result.answer)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Optimized RAG
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from dspy.teleprompt import BootstrapFewShot
|
|
50
|
+
|
|
51
|
+
# Training data with question-answer pairs
|
|
52
|
+
trainset = [
|
|
53
|
+
dspy.Example(
|
|
54
|
+
question="What is retrieval augmented generation?",
|
|
55
|
+
answer="RAG combines retrieval of relevant documents with generation..."
|
|
56
|
+
).with_inputs("question"),
|
|
57
|
+
# ... more examples
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
# Define metric
|
|
61
|
+
def answer_correctness(example, pred, trace=None):
|
|
62
|
+
# Check if answer contains key information
|
|
63
|
+
return example.answer.lower() in pred.answer.lower()
|
|
64
|
+
|
|
65
|
+
# Optimize RAG
|
|
66
|
+
optimizer = BootstrapFewShot(metric=answer_correctness)
|
|
67
|
+
optimized_rag = optimizer.compile(rag, trainset=trainset)
|
|
68
|
+
|
|
69
|
+
# Optimized RAG performs better on similar questions
|
|
70
|
+
result = optimized_rag(question="Explain RAG systems")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Multi-Hop RAG
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
class MultiHopRAG(dspy.Module):
|
|
77
|
+
"""RAG that follows chains of reasoning across documents."""
|
|
78
|
+
|
|
79
|
+
def __init__(self):
|
|
80
|
+
super().__init__()
|
|
81
|
+
self.retrieve = dspy.Retrieve(k=3)
|
|
82
|
+
self.generate_query = dspy.ChainOfThought("question -> search_query")
|
|
83
|
+
self.generate_answer = dspy.ChainOfThought("context, question -> answer")
|
|
84
|
+
|
|
85
|
+
def forward(self, question):
|
|
86
|
+
# First retrieval
|
|
87
|
+
query1 = self.generate_query(question=question).search_query
|
|
88
|
+
passages1 = self.retrieve(query1).passages
|
|
89
|
+
|
|
90
|
+
# Generate follow-up query based on first results
|
|
91
|
+
context1 = "\n".join(passages1)
|
|
92
|
+
query2 = self.generate_query(
|
|
93
|
+
question=f"Based on: {context1}\nFollow-up: {question}"
|
|
94
|
+
).search_query
|
|
95
|
+
|
|
96
|
+
# Second retrieval
|
|
97
|
+
passages2 = self.retrieve(query2).passages
|
|
98
|
+
|
|
99
|
+
# Combine all context
|
|
100
|
+
all_context = "\n\n".join(passages1 + passages2)
|
|
101
|
+
|
|
102
|
+
# Generate final answer
|
|
103
|
+
return self.generate_answer(context=all_context, question=question)
|
|
104
|
+
|
|
105
|
+
# Use multi-hop RAG
|
|
106
|
+
multi_rag = MultiHopRAG()
|
|
107
|
+
result = multi_rag(question="Who wrote the book that inspired Blade Runner?")
|
|
108
|
+
# Hop 1: Find "Blade Runner was based on..."
|
|
109
|
+
# Hop 2: Find author of that book
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### RAG with Reranking
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
class RerankedRAG(dspy.Module):
|
|
116
|
+
"""RAG with learned reranking of retrieved passages."""
|
|
117
|
+
|
|
118
|
+
def __init__(self):
|
|
119
|
+
super().__init__()
|
|
120
|
+
self.retrieve = dspy.Retrieve(k=10) # Get more candidates
|
|
121
|
+
self.rerank = dspy.Predict("question, passage -> relevance_score: float")
|
|
122
|
+
self.answer = dspy.ChainOfThought("context, question -> answer")
|
|
123
|
+
|
|
124
|
+
def forward(self, question):
|
|
125
|
+
# Retrieve candidates
|
|
126
|
+
passages = self.retrieve(question).passages
|
|
127
|
+
|
|
128
|
+
# Rerank passages
|
|
129
|
+
scored_passages = []
|
|
130
|
+
for passage in passages:
|
|
131
|
+
score = float(self.rerank(
|
|
132
|
+
question=question,
|
|
133
|
+
passage=passage
|
|
134
|
+
).relevance_score)
|
|
135
|
+
scored_passages.append((score, passage))
|
|
136
|
+
|
|
137
|
+
# Take top 3 after reranking
|
|
138
|
+
top_passages = [p for _, p in sorted(scored_passages, reverse=True)[:3]]
|
|
139
|
+
context = "\n\n".join(top_passages)
|
|
140
|
+
|
|
141
|
+
# Generate answer from reranked context
|
|
142
|
+
return self.answer(context=context, question=question)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Agent Systems
|
|
146
|
+
|
|
147
|
+
### ReAct Agent
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from dspy.predict import ReAct
|
|
151
|
+
|
|
152
|
+
# Define tools
|
|
153
|
+
def search_wikipedia(query: str) -> str:
|
|
154
|
+
"""Search Wikipedia for information."""
|
|
155
|
+
import wikipedia
|
|
156
|
+
try:
|
|
157
|
+
return wikipedia.summary(query, sentences=3)
|
|
158
|
+
except:
|
|
159
|
+
return "No results found"
|
|
160
|
+
|
|
161
|
+
def calculate(expression: str) -> str:
|
|
162
|
+
"""Evaluate mathematical expression safely."""
|
|
163
|
+
try:
|
|
164
|
+
# Use safe eval
|
|
165
|
+
result = eval(expression, {"__builtins__": {}}, {})
|
|
166
|
+
return str(result)
|
|
167
|
+
except:
|
|
168
|
+
return "Invalid expression"
|
|
169
|
+
|
|
170
|
+
def search_web(query: str) -> str:
|
|
171
|
+
"""Search the web."""
|
|
172
|
+
# Your web search implementation
|
|
173
|
+
return results
|
|
174
|
+
|
|
175
|
+
# Create agent signature
|
|
176
|
+
class ResearchAgent(dspy.Signature):
|
|
177
|
+
"""Answer questions using available tools."""
|
|
178
|
+
question = dspy.InputField()
|
|
179
|
+
answer = dspy.OutputField()
|
|
180
|
+
|
|
181
|
+
# Create ReAct agent
|
|
182
|
+
agent = ReAct(ResearchAgent, tools=[search_wikipedia, calculate, search_web])
|
|
183
|
+
|
|
184
|
+
# Agent decides which tools to use
|
|
185
|
+
result = agent(question="What is the population of France divided by 10?")
|
|
186
|
+
# Agent:
|
|
187
|
+
# 1. Thinks: "Need population of France"
|
|
188
|
+
# 2. Acts: search_wikipedia("France population")
|
|
189
|
+
# 3. Thinks: "Got 67 million, need to divide"
|
|
190
|
+
# 4. Acts: calculate("67000000 / 10")
|
|
191
|
+
# 5. Returns: "6,700,000"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Multi-Agent System
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
class MultiAgentSystem(dspy.Module):
|
|
198
|
+
"""System with specialized agents for different tasks."""
|
|
199
|
+
|
|
200
|
+
def __init__(self):
|
|
201
|
+
super().__init__()
|
|
202
|
+
|
|
203
|
+
# Router agent
|
|
204
|
+
self.router = dspy.Predict("question -> agent_type: str")
|
|
205
|
+
|
|
206
|
+
# Specialized agents
|
|
207
|
+
self.research_agent = ReAct(
|
|
208
|
+
ResearchAgent,
|
|
209
|
+
tools=[search_wikipedia, search_web]
|
|
210
|
+
)
|
|
211
|
+
self.math_agent = dspy.ProgramOfThought("problem -> answer")
|
|
212
|
+
self.reasoning_agent = dspy.ChainOfThought("question -> answer")
|
|
213
|
+
|
|
214
|
+
def forward(self, question):
|
|
215
|
+
# Route to appropriate agent
|
|
216
|
+
agent_type = self.router(question=question).agent_type
|
|
217
|
+
|
|
218
|
+
if agent_type == "research":
|
|
219
|
+
return self.research_agent(question=question)
|
|
220
|
+
elif agent_type == "math":
|
|
221
|
+
return self.math_agent(problem=question)
|
|
222
|
+
else:
|
|
223
|
+
return self.reasoning_agent(question=question)
|
|
224
|
+
|
|
225
|
+
# Use multi-agent system
|
|
226
|
+
mas = MultiAgentSystem()
|
|
227
|
+
result = mas(question="What is 15% of the GDP of France?")
|
|
228
|
+
# Routes to research_agent for GDP, then to math_agent for calculation
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Classification
|
|
232
|
+
|
|
233
|
+
### Binary Classifier
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
class SentimentClassifier(dspy.Module):
|
|
237
|
+
def __init__(self):
|
|
238
|
+
super().__init__()
|
|
239
|
+
self.classify = dspy.Predict("text -> sentiment: str")
|
|
240
|
+
|
|
241
|
+
def forward(self, text):
|
|
242
|
+
return self.classify(text=text)
|
|
243
|
+
|
|
244
|
+
# Training data
|
|
245
|
+
trainset = [
|
|
246
|
+
dspy.Example(text="I love this!", sentiment="positive").with_inputs("text"),
|
|
247
|
+
dspy.Example(text="Terrible experience", sentiment="negative").with_inputs("text"),
|
|
248
|
+
# ... more examples
|
|
249
|
+
]
|
|
250
|
+
|
|
251
|
+
# Optimize
|
|
252
|
+
def accuracy(example, pred, trace=None):
|
|
253
|
+
return example.sentiment == pred.sentiment
|
|
254
|
+
|
|
255
|
+
optimizer = BootstrapFewShot(metric=accuracy, max_bootstrapped_demos=5)
|
|
256
|
+
classifier = SentimentClassifier()
|
|
257
|
+
optimized_classifier = optimizer.compile(classifier, trainset=trainset)
|
|
258
|
+
|
|
259
|
+
# Use classifier
|
|
260
|
+
result = optimized_classifier(text="This product is amazing!")
|
|
261
|
+
print(result.sentiment) # "positive"
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Multi-Class Classifier
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
class TopicClassifier(dspy.Module):
|
|
268
|
+
def __init__(self):
|
|
269
|
+
super().__init__()
|
|
270
|
+
self.classify = dspy.ChainOfThought(
|
|
271
|
+
"text -> category: str, confidence: float"
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
def forward(self, text):
|
|
275
|
+
result = self.classify(text=text)
|
|
276
|
+
return dspy.Prediction(
|
|
277
|
+
category=result.category,
|
|
278
|
+
confidence=float(result.confidence)
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
# Define categories in signature
|
|
282
|
+
class TopicSignature(dspy.Signature):
|
|
283
|
+
"""Classify text into one of: technology, sports, politics, entertainment."""
|
|
284
|
+
text = dspy.InputField()
|
|
285
|
+
category = dspy.OutputField(desc="one of: technology, sports, politics, entertainment")
|
|
286
|
+
confidence = dspy.OutputField(desc="0.0 to 1.0")
|
|
287
|
+
|
|
288
|
+
classifier = dspy.ChainOfThought(TopicSignature)
|
|
289
|
+
result = classifier(text="The Lakers won the championship")
|
|
290
|
+
print(result.category) # "sports"
|
|
291
|
+
print(result.confidence) # 0.95
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Hierarchical Classifier
|
|
295
|
+
|
|
296
|
+
```python
|
|
297
|
+
class HierarchicalClassifier(dspy.Module):
|
|
298
|
+
"""Two-stage classification: coarse then fine-grained."""
|
|
299
|
+
|
|
300
|
+
def __init__(self):
|
|
301
|
+
super().__init__()
|
|
302
|
+
self.coarse = dspy.Predict("text -> broad_category: str")
|
|
303
|
+
self.fine_tech = dspy.Predict("text -> tech_subcategory: str")
|
|
304
|
+
self.fine_sports = dspy.Predict("text -> sports_subcategory: str")
|
|
305
|
+
|
|
306
|
+
def forward(self, text):
|
|
307
|
+
# Stage 1: Broad category
|
|
308
|
+
broad = self.coarse(text=text).broad_category
|
|
309
|
+
|
|
310
|
+
# Stage 2: Fine-grained based on broad
|
|
311
|
+
if broad == "technology":
|
|
312
|
+
fine = self.fine_tech(text=text).tech_subcategory
|
|
313
|
+
elif broad == "sports":
|
|
314
|
+
fine = self.fine_sports(text=text).sports_subcategory
|
|
315
|
+
else:
|
|
316
|
+
fine = "other"
|
|
317
|
+
|
|
318
|
+
return dspy.Prediction(broad_category=broad, fine_category=fine)
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Data Processing
|
|
322
|
+
|
|
323
|
+
### Text Summarization
|
|
324
|
+
|
|
325
|
+
```python
|
|
326
|
+
class AdaptiveSummarizer(dspy.Module):
|
|
327
|
+
"""Summarizes text to target length."""
|
|
328
|
+
|
|
329
|
+
def __init__(self):
|
|
330
|
+
super().__init__()
|
|
331
|
+
self.summarize = dspy.ChainOfThought("text, target_length -> summary")
|
|
332
|
+
|
|
333
|
+
def forward(self, text, target_length="3 sentences"):
|
|
334
|
+
return self.summarize(text=text, target_length=target_length)
|
|
335
|
+
|
|
336
|
+
# Use summarizer
|
|
337
|
+
summarizer = AdaptiveSummarizer()
|
|
338
|
+
long_text = "..." # Long article
|
|
339
|
+
|
|
340
|
+
short_summary = summarizer(long_text, target_length="1 sentence")
|
|
341
|
+
medium_summary = summarizer(long_text, target_length="3 sentences")
|
|
342
|
+
detailed_summary = summarizer(long_text, target_length="1 paragraph")
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### Information Extraction
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
from pydantic import BaseModel, Field
|
|
349
|
+
|
|
350
|
+
class PersonInfo(BaseModel):
|
|
351
|
+
name: str = Field(description="Full name")
|
|
352
|
+
age: int = Field(description="Age in years")
|
|
353
|
+
occupation: str = Field(description="Job title")
|
|
354
|
+
location: str = Field(description="City and country")
|
|
355
|
+
|
|
356
|
+
class ExtractPerson(dspy.Signature):
|
|
357
|
+
"""Extract person information from text."""
|
|
358
|
+
text = dspy.InputField()
|
|
359
|
+
person: PersonInfo = dspy.OutputField()
|
|
360
|
+
|
|
361
|
+
extractor = dspy.TypedPredictor(ExtractPerson)
|
|
362
|
+
|
|
363
|
+
text = "Dr. Jane Smith, 42, is a neuroscientist at Stanford University in Palo Alto, California."
|
|
364
|
+
result = extractor(text=text)
|
|
365
|
+
|
|
366
|
+
print(result.person.name) # "Dr. Jane Smith"
|
|
367
|
+
print(result.person.age) # 42
|
|
368
|
+
print(result.person.occupation) # "neuroscientist"
|
|
369
|
+
print(result.person.location) # "Palo Alto, California"
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Batch Processing
|
|
373
|
+
|
|
374
|
+
```python
|
|
375
|
+
class BatchProcessor(dspy.Module):
|
|
376
|
+
"""Process large datasets efficiently."""
|
|
377
|
+
|
|
378
|
+
def __init__(self):
|
|
379
|
+
super().__init__()
|
|
380
|
+
self.process = dspy.Predict("text -> processed_text")
|
|
381
|
+
|
|
382
|
+
def forward(self, texts):
|
|
383
|
+
# Batch processing for efficiency
|
|
384
|
+
return self.process.batch([{"text": t} for t in texts])
|
|
385
|
+
|
|
386
|
+
# Process 1000 documents
|
|
387
|
+
processor = BatchProcessor()
|
|
388
|
+
results = processor(texts=large_dataset)
|
|
389
|
+
|
|
390
|
+
# Results are returned in order
|
|
391
|
+
for original, result in zip(large_dataset, results):
|
|
392
|
+
print(f"{original} -> {result.processed_text}")
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
## Multi-Stage Pipelines
|
|
396
|
+
|
|
397
|
+
### Document Processing Pipeline
|
|
398
|
+
|
|
399
|
+
```python
|
|
400
|
+
class DocumentPipeline(dspy.Module):
|
|
401
|
+
"""Multi-stage document processing."""
|
|
402
|
+
|
|
403
|
+
def __init__(self):
|
|
404
|
+
super().__init__()
|
|
405
|
+
self.extract = dspy.Predict("document -> key_points")
|
|
406
|
+
self.classify = dspy.Predict("key_points -> category")
|
|
407
|
+
self.summarize = dspy.ChainOfThought("key_points, category -> summary")
|
|
408
|
+
self.tag = dspy.Predict("summary -> tags")
|
|
409
|
+
|
|
410
|
+
def forward(self, document):
|
|
411
|
+
# Stage 1: Extract key points
|
|
412
|
+
key_points = self.extract(document=document).key_points
|
|
413
|
+
|
|
414
|
+
# Stage 2: Classify
|
|
415
|
+
category = self.classify(key_points=key_points).category
|
|
416
|
+
|
|
417
|
+
# Stage 3: Summarize
|
|
418
|
+
summary = self.summarize(
|
|
419
|
+
key_points=key_points,
|
|
420
|
+
category=category
|
|
421
|
+
).summary
|
|
422
|
+
|
|
423
|
+
# Stage 4: Generate tags
|
|
424
|
+
tags = self.tag(summary=summary).tags
|
|
425
|
+
|
|
426
|
+
return dspy.Prediction(
|
|
427
|
+
key_points=key_points,
|
|
428
|
+
category=category,
|
|
429
|
+
summary=summary,
|
|
430
|
+
tags=tags
|
|
431
|
+
)
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### Quality Control Pipeline
|
|
435
|
+
|
|
436
|
+
```python
|
|
437
|
+
class QualityControlPipeline(dspy.Module):
|
|
438
|
+
"""Generate output and verify quality."""
|
|
439
|
+
|
|
440
|
+
def __init__(self):
|
|
441
|
+
super().__init__()
|
|
442
|
+
self.generate = dspy.ChainOfThought("prompt -> output")
|
|
443
|
+
self.verify = dspy.Predict("output -> is_valid: bool, issues: str")
|
|
444
|
+
self.improve = dspy.ChainOfThought("output, issues -> improved_output")
|
|
445
|
+
|
|
446
|
+
def forward(self, prompt, max_iterations=3):
|
|
447
|
+
output = self.generate(prompt=prompt).output
|
|
448
|
+
|
|
449
|
+
for _ in range(max_iterations):
|
|
450
|
+
# Verify output
|
|
451
|
+
verification = self.verify(output=output)
|
|
452
|
+
|
|
453
|
+
if verification.is_valid:
|
|
454
|
+
return dspy.Prediction(output=output, iterations=_ + 1)
|
|
455
|
+
|
|
456
|
+
# Improve based on issues
|
|
457
|
+
output = self.improve(
|
|
458
|
+
output=output,
|
|
459
|
+
issues=verification.issues
|
|
460
|
+
).improved_output
|
|
461
|
+
|
|
462
|
+
return dspy.Prediction(output=output, iterations=max_iterations)
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
## Production Tips
|
|
466
|
+
|
|
467
|
+
### 1. Caching for Performance
|
|
468
|
+
|
|
469
|
+
```python
|
|
470
|
+
from functools import lru_cache
|
|
471
|
+
|
|
472
|
+
class CachedRAG(dspy.Module):
|
|
473
|
+
def __init__(self):
|
|
474
|
+
super().__init__()
|
|
475
|
+
self.retrieve = dspy.Retrieve(k=3)
|
|
476
|
+
self.generate = dspy.ChainOfThought("context, question -> answer")
|
|
477
|
+
|
|
478
|
+
@lru_cache(maxsize=1000)
|
|
479
|
+
def forward(self, question):
|
|
480
|
+
passages = self.retrieve(question).passages
|
|
481
|
+
context = "\n".join(passages)
|
|
482
|
+
return self.generate(context=context, question=question).answer
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### 2. Error Handling
|
|
486
|
+
|
|
487
|
+
```python
|
|
488
|
+
class RobustModule(dspy.Module):
|
|
489
|
+
def __init__(self):
|
|
490
|
+
super().__init__()
|
|
491
|
+
self.process = dspy.ChainOfThought("input -> output")
|
|
492
|
+
|
|
493
|
+
def forward(self, input):
|
|
494
|
+
try:
|
|
495
|
+
result = self.process(input=input)
|
|
496
|
+
return result
|
|
497
|
+
except Exception as e:
|
|
498
|
+
# Log error
|
|
499
|
+
print(f"Error processing {input}: {e}")
|
|
500
|
+
# Return fallback
|
|
501
|
+
return dspy.Prediction(output="Error: could not process input")
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### 3. Monitoring
|
|
505
|
+
|
|
506
|
+
```python
|
|
507
|
+
class MonitoredModule(dspy.Module):
|
|
508
|
+
def __init__(self):
|
|
509
|
+
super().__init__()
|
|
510
|
+
self.process = dspy.ChainOfThought("input -> output")
|
|
511
|
+
self.call_count = 0
|
|
512
|
+
self.errors = 0
|
|
513
|
+
|
|
514
|
+
def forward(self, input):
|
|
515
|
+
self.call_count += 1
|
|
516
|
+
|
|
517
|
+
try:
|
|
518
|
+
result = self.process(input=input)
|
|
519
|
+
return result
|
|
520
|
+
except Exception as e:
|
|
521
|
+
self.errors += 1
|
|
522
|
+
raise
|
|
523
|
+
|
|
524
|
+
def get_stats(self):
|
|
525
|
+
return {
|
|
526
|
+
"calls": self.call_count,
|
|
527
|
+
"errors": self.errors,
|
|
528
|
+
"error_rate": self.errors / max(self.call_count, 1)
|
|
529
|
+
}
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### 4. A/B Testing
|
|
533
|
+
|
|
534
|
+
```python
|
|
535
|
+
class ABTestModule(dspy.Module):
|
|
536
|
+
"""Run two variants and compare."""
|
|
537
|
+
|
|
538
|
+
def __init__(self, variant_a, variant_b):
|
|
539
|
+
super().__init__()
|
|
540
|
+
self.variant_a = variant_a
|
|
541
|
+
self.variant_b = variant_b
|
|
542
|
+
self.a_calls = 0
|
|
543
|
+
self.b_calls = 0
|
|
544
|
+
|
|
545
|
+
def forward(self, input, variant="a"):
|
|
546
|
+
if variant == "a":
|
|
547
|
+
self.a_calls += 1
|
|
548
|
+
return self.variant_a(input=input)
|
|
549
|
+
else:
|
|
550
|
+
self.b_calls += 1
|
|
551
|
+
return self.variant_b(input=input)
|
|
552
|
+
|
|
553
|
+
# Compare two optimizers
|
|
554
|
+
baseline = dspy.ChainOfThought("question -> answer")
|
|
555
|
+
optimized = BootstrapFewShot(...).compile(baseline, trainset=trainset)
|
|
556
|
+
|
|
557
|
+
ab_test = ABTestModule(variant_a=baseline, variant_b=optimized)
|
|
558
|
+
|
|
559
|
+
# Route 50% to each
|
|
560
|
+
import random
|
|
561
|
+
variant = "a" if random.random() < 0.5 else "b"
|
|
562
|
+
result = ab_test(input=question, variant=variant)
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
## Complete Example: Customer Support Bot
|
|
566
|
+
|
|
567
|
+
```python
|
|
568
|
+
import dspy
|
|
569
|
+
from dspy.teleprompt import BootstrapFewShot
|
|
570
|
+
|
|
571
|
+
class CustomerSupportBot(dspy.Module):
|
|
572
|
+
"""Complete customer support system."""
|
|
573
|
+
|
|
574
|
+
def __init__(self):
|
|
575
|
+
super().__init__()
|
|
576
|
+
|
|
577
|
+
# Classify intent
|
|
578
|
+
self.classify_intent = dspy.Predict("message -> intent: str")
|
|
579
|
+
|
|
580
|
+
# Specialized handlers
|
|
581
|
+
self.technical_handler = dspy.ChainOfThought("message, history -> response")
|
|
582
|
+
self.billing_handler = dspy.ChainOfThought("message, history -> response")
|
|
583
|
+
self.general_handler = dspy.Predict("message, history -> response")
|
|
584
|
+
|
|
585
|
+
# Retrieve relevant docs
|
|
586
|
+
self.retrieve = dspy.Retrieve(k=3)
|
|
587
|
+
|
|
588
|
+
# Conversation history
|
|
589
|
+
self.history = []
|
|
590
|
+
|
|
591
|
+
def forward(self, message):
|
|
592
|
+
# Classify intent
|
|
593
|
+
intent = self.classify_intent(message=message).intent
|
|
594
|
+
|
|
595
|
+
# Retrieve relevant documentation
|
|
596
|
+
docs = self.retrieve(message).passages
|
|
597
|
+
context = "\n".join(docs)
|
|
598
|
+
|
|
599
|
+
# Add context to history
|
|
600
|
+
history_str = "\n".join(self.history)
|
|
601
|
+
full_message = f"Context: {context}\n\nMessage: {message}"
|
|
602
|
+
|
|
603
|
+
# Route to appropriate handler
|
|
604
|
+
if intent == "technical":
|
|
605
|
+
response = self.technical_handler(
|
|
606
|
+
message=full_message,
|
|
607
|
+
history=history_str
|
|
608
|
+
).response
|
|
609
|
+
elif intent == "billing":
|
|
610
|
+
response = self.billing_handler(
|
|
611
|
+
message=full_message,
|
|
612
|
+
history=history_str
|
|
613
|
+
).response
|
|
614
|
+
else:
|
|
615
|
+
response = self.general_handler(
|
|
616
|
+
message=full_message,
|
|
617
|
+
history=history_str
|
|
618
|
+
).response
|
|
619
|
+
|
|
620
|
+
# Update history
|
|
621
|
+
self.history.append(f"User: {message}")
|
|
622
|
+
self.history.append(f"Bot: {response}")
|
|
623
|
+
|
|
624
|
+
return dspy.Prediction(response=response, intent=intent)
|
|
625
|
+
|
|
626
|
+
# Training data
|
|
627
|
+
trainset = [
|
|
628
|
+
dspy.Example(
|
|
629
|
+
message="My account isn't working",
|
|
630
|
+
intent="technical",
|
|
631
|
+
response="I'd be happy to help. What error are you seeing?"
|
|
632
|
+
).with_inputs("message"),
|
|
633
|
+
# ... more examples
|
|
634
|
+
]
|
|
635
|
+
|
|
636
|
+
# Define metric
|
|
637
|
+
def response_quality(example, pred, trace=None):
|
|
638
|
+
# Check if response is helpful
|
|
639
|
+
if len(pred.response) < 20:
|
|
640
|
+
return 0.0
|
|
641
|
+
if example.intent != pred.intent:
|
|
642
|
+
return 0.3
|
|
643
|
+
return 1.0
|
|
644
|
+
|
|
645
|
+
# Optimize
|
|
646
|
+
optimizer = BootstrapFewShot(metric=response_quality)
|
|
647
|
+
bot = CustomerSupportBot()
|
|
648
|
+
optimized_bot = optimizer.compile(bot, trainset=trainset)
|
|
649
|
+
|
|
650
|
+
# Use in production
|
|
651
|
+
optimized_bot.save("models/support_bot_v1.json")
|
|
652
|
+
|
|
653
|
+
# Later, load and use
|
|
654
|
+
loaded_bot = CustomerSupportBot()
|
|
655
|
+
loaded_bot.load("models/support_bot_v1.json")
|
|
656
|
+
response = loaded_bot(message="I can't log in")
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
## Resources
|
|
660
|
+
|
|
661
|
+
- **Documentation**: https://dspy.ai
|
|
662
|
+
- **Examples Repo**: https://github.com/stanfordnlp/dspy/tree/main/examples
|
|
663
|
+
- **Discord**: https://discord.gg/XCGy2WDCQB
|