castform 0.2.3__tar.gz → 0.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. {castform-0.2.3 → castform-0.2.4}/PKG-INFO +3 -3
  2. {castform-0.2.3 → castform-0.2.4}/pyproject.toml +2 -2
  3. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/CLAUDE.md +6 -0
  4. castform-0.2.4/src/castform/cli/scaffold/skills/train-sft/SKILL.md +141 -0
  5. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/setup.py +1 -0
  6. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/__init__.py +4 -0
  7. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/client.py +82 -1
  8. castform-0.2.4/src/castform/platform/sft.py +363 -0
  9. {castform-0.2.3 → castform-0.2.4}/tests/unit/platform/test_client.py +1 -3
  10. castform-0.2.4/tests/unit/platform/test_sft.py +581 -0
  11. {castform-0.2.3 → castform-0.2.4}/.gitignore +0 -0
  12. {castform-0.2.3 → castform-0.2.4}/README.md +0 -0
  13. {castform-0.2.3 → castform-0.2.4}/pytest.ini +0 -0
  14. {castform-0.2.3 → castform-0.2.4}/src/castform/__init__.py +0 -0
  15. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/__init__.py +0 -0
  16. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/_auth.py +0 -0
  17. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/_client.py +0 -0
  18. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/_output.py +0 -0
  19. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/_preflight.py +0 -0
  20. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/control.py +0 -0
  21. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/doctor.py +0 -0
  22. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/help.py +0 -0
  23. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/runs.py +0 -0
  24. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/HARBOR_STARTER.md +0 -0
  25. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/STARTER.md +0 -0
  26. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/__init__.py +0 -0
  27. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/generic_env_tests.py +0 -0
  28. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/generic_eval_dataset.jsonl +0 -0
  29. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/generic_main.py +0 -0
  30. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/generic_train_dataset.jsonl +0 -0
  31. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/harbor_env_tests.py +0 -0
  32. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/harbor_main.py +0 -0
  33. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/skills/design-environment/SKILL.md +0 -0
  34. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/skills/generate-data/SKILL.md +0 -0
  35. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/skills/launch-run/SKILL.md +0 -0
  36. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/skills/verify-environment/SKILL.md +0 -0
  37. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/skills/view-progress/SKILL.md +0 -0
  38. {castform-0.2.3 → castform-0.2.4}/src/castform/cli/scaffold/tests_conftest.py +0 -0
  39. {castform-0.2.3 → castform-0.2.4}/src/castform/config.py +0 -0
  40. {castform-0.2.3 → castform-0.2.4}/src/castform/model_auth.py +0 -0
  41. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/browser.py +0 -0
  42. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/config.py +0 -0
  43. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/credentials.py +0 -0
  44. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/device_auth.py +0 -0
  45. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/environment_assets.py +0 -0
  46. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/exceptions.py +0 -0
  47. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/login.py +0 -0
  48. {castform-0.2.3 → castform-0.2.4}/src/castform/platform/model_session.py +0 -0
  49. {castform-0.2.3 → castform-0.2.4}/src/castform/profile_config.py +0 -0
  50. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/chunkers/__init__.py +0 -0
  51. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/chunkers/email.py +0 -0
  52. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/chunkers/inspector.py +0 -0
  53. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/chunkers/markdown.py +0 -0
  54. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/chunkers/models.py +0 -0
  55. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/chunkers/storage.py +0 -0
  56. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/__init__.py +0 -0
  57. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/chroma/__init__.py +0 -0
  58. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/chroma/client.py +0 -0
  59. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/chroma/files.py +0 -0
  60. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/chroma/filter_mapper.py +0 -0
  61. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/chroma/source.py +0 -0
  62. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/pinecone/__init__.py +0 -0
  63. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/pinecone/files.py +0 -0
  64. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/pinecone/filter_mapper.py +0 -0
  65. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/pinecone/index_client.py +0 -0
  66. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/pinecone/source.py +0 -0
  67. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/postgres/__init__.py +0 -0
  68. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/postgres/client.py +0 -0
  69. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/postgres/exceptions.py +0 -0
  70. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/postgres/filter_mapper.py +0 -0
  71. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/postgres/models.py +0 -0
  72. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/postgres/source.py +0 -0
  73. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/search_schema/__init__.py +0 -0
  74. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/search_schema/builders.py +0 -0
  75. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/search_schema/dsl_parser.py +0 -0
  76. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/search_schema/search_exceptions.py +0 -0
  77. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/search_schema/search_types.py +0 -0
  78. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/source.py +0 -0
  79. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/turbopuffer/__init__.py +0 -0
  80. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/turbopuffer/files.py +0 -0
  81. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/turbopuffer/filter_mapper.py +0 -0
  82. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/turbopuffer/namespace.py +0 -0
  83. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/corpus/turbopuffer/source.py +0 -0
  84. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/example_data.py +0 -0
  85. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/preprocess/__init__.py +0 -0
  86. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/preprocess/email/__init__.py +0 -0
  87. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/preprocess/email/clean_bodies.py +0 -0
  88. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/preprocess/email/dedupe.py +0 -0
  89. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/preprocess/email/filter_automated_email_qas.py +0 -0
  90. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/preprocess/email/filter_automated_emails.py +0 -0
  91. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/preprocess/email/mbox.py +0 -0
  92. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/preprocess/email/schema.py +0 -0
  93. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/__init__.py +0 -0
  94. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/anchor_selector.py +0 -0
  95. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/auto_tune.py +0 -0
  96. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/batch_processor.py +0 -0
  97. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/checkpoint.py +0 -0
  98. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/corpus_capabilities.py +0 -0
  99. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/corpus_profile.py +0 -0
  100. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/filters/__init__.py +0 -0
  101. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/filters/deterministic_guards.py +0 -0
  102. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/filters/grounding_llm.py +0 -0
  103. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/filters/hop_count_validity.py +0 -0
  104. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/filters/quality_gate.py +0 -0
  105. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/filters/retrieval_llm.py +0 -0
  106. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/formatters/__init__.py +0 -0
  107. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/formatters/train_eval.py +0 -0
  108. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/generated_qa.py +0 -0
  109. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/generators/__init__.py +0 -0
  110. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/generators/direct_llm.py +0 -0
  111. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/helpers.py +0 -0
  112. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/metadata_linker.py +0 -0
  113. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/metrics.py +0 -0
  114. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/models.py +0 -0
  115. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/pipeline.py +0 -0
  116. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/pipeline_config.py +0 -0
  117. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/protocols.py +0 -0
  118. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/query_rewriter.py +0 -0
  119. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/response_parsers.py +0 -0
  120. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/retrieval_query.py +0 -0
  121. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/scoring.py +0 -0
  122. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/storage.py +0 -0
  123. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/style_controls.py +0 -0
  124. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/transformers/__init__.py +0 -0
  125. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/transformers/base.py +0 -0
  126. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/transformers/dedup.py +0 -0
  127. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/wiki_builder.py +0 -0
  128. {castform-0.2.3 → castform-0.2.4}/src/castform/rag/qa_generation/wiki_chunk_linker.py +0 -0
  129. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/__init__.py +0 -0
  130. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/adapter.py +0 -0
  131. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/braintrust/__init__.py +0 -0
  132. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/braintrust/adapter.py +0 -0
  133. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/braintrust/message_extraction.py +0 -0
  134. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/http.py +0 -0
  135. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/pipeline.py +0 -0
  136. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/pivot.py +0 -0
  137. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/processing.py +0 -0
  138. {castform-0.2.3 → castform-0.2.4}/src/castform/traces/registry.py +0 -0
  139. {castform-0.2.3 → castform-0.2.4}/src/castform/utils/__init__.py +0 -0
  140. {castform-0.2.3 → castform-0.2.4}/src/castform/utils/checkpoint.py +0 -0
  141. {castform-0.2.3 → castform-0.2.4}/src/castform/validation.py +0 -0
  142. {castform-0.2.3 → castform-0.2.4}/tests/conftest.py +0 -0
  143. {castform-0.2.3 → castform-0.2.4}/tests/integration/harbor/README.md +0 -0
  144. {castform-0.2.3 → castform-0.2.4}/tests/integration/harbor/test_harbor_modal_live.py +0 -0
  145. {castform-0.2.3 → castform-0.2.4}/tests/integration/platform/test_rollout_reads.py +0 -0
  146. {castform-0.2.3 → castform-0.2.4}/tests/integration/test_async_corpus_client.py +0 -0
  147. {castform-0.2.3 → castform-0.2.4}/tests/integration/test_diversity_llm.py +0 -0
  148. {castform-0.2.3 → castform-0.2.4}/tests/integration/test_rubric_auth_retry.py +0 -0
  149. {castform-0.2.3 → castform-0.2.4}/tests/integration/traces/test_braintrust_e2e.py +0 -0
  150. {castform-0.2.3 → castform-0.2.4}/tests/unit/_scaffold.py +0 -0
  151. {castform-0.2.3 → castform-0.2.4}/tests/unit/cli_help.golden +0 -0
  152. {castform-0.2.3 → castform-0.2.4}/tests/unit/platform/test_credentials.py +0 -0
  153. {castform-0.2.3 → castform-0.2.4}/tests/unit/platform/test_device_auth.py +0 -0
  154. {castform-0.2.3 → castform-0.2.4}/tests/unit/platform/test_environment_assets.py +0 -0
  155. {castform-0.2.3 → castform-0.2.4}/tests/unit/platform/test_keyless_public_api.py +0 -0
  156. {castform-0.2.3 → castform-0.2.4}/tests/unit/platform/test_model_session.py +0 -0
  157. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/chunkers/test_builders.py +0 -0
  158. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/chunkers/test_chunk_models.py +0 -0
  159. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/conftest.py +0 -0
  160. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/chroma/test_configurations.py +0 -0
  161. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/chroma/test_filter_mapper.py +0 -0
  162. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/chroma/test_search_related.py +0 -0
  163. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/pinecone/test_configurations.py +0 -0
  164. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/pinecone/test_filter_mapper.py +0 -0
  165. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/pinecone/test_search_related.py +0 -0
  166. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/pinecone/test_sparse_and_sampling.py +0 -0
  167. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/postgres/test_async_client.py +0 -0
  168. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/postgres/test_filter_mapper.py +0 -0
  169. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/postgres/test_search_related.py +0 -0
  170. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/postgres/test_source.py +0 -0
  171. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/test_dsl_parser.py +0 -0
  172. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/test_protocol_conformance.py +0 -0
  173. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/test_search_types.py +0 -0
  174. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/tpuf/test_configurations.py +0 -0
  175. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/tpuf/test_content_field.py +0 -0
  176. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/tpuf/test_filter_mapper.py +0 -0
  177. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/tpuf/test_hybrid_search.py +0 -0
  178. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/tpuf/test_namespace.py +0 -0
  179. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/corpus/tpuf/test_search_related.py +0 -0
  180. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/fakes/chroma.py +0 -0
  181. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/fakes/pinecone.py +0 -0
  182. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/qa_generation/test_async_cleanup.py +0 -0
  183. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/qa_generation/test_batch_processor_async.py +0 -0
  184. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/qa_generation/test_filter_and_sample_seeds.py +0 -0
  185. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/qa_generation/test_grounding_batch_isolation.py +0 -0
  186. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/qa_generation/test_grounding_removed_chunks.py +0 -0
  187. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_auto_tune.py +0 -0
  188. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_checkpoint_base.py +0 -0
  189. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_chunkers.py +0 -0
  190. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_corpus_profile.py +0 -0
  191. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_dedup.py +0 -0
  192. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_deterministic_guards.py +0 -0
  193. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_entity_quality.py +0 -0
  194. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_example_data.py +0 -0
  195. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_hop_count_validity.py +0 -0
  196. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_keybert_extraction.py +0 -0
  197. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_metadata_linker.py +0 -0
  198. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_micro_batch.py +0 -0
  199. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_relabel_qa_types.py +0 -0
  200. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_wiki_builder.py +0 -0
  201. {castform-0.2.3 → castform-0.2.4}/tests/unit/rag/test_wiki_chunk_linker.py +0 -0
  202. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_cli.py +0 -0
  203. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_cli_control.py +0 -0
  204. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_cli_doctor.py +0 -0
  205. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_cli_help.py +0 -0
  206. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_cli_help_render.py +0 -0
  207. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_cli_output.py +0 -0
  208. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_cli_preflight.py +0 -0
  209. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_cli_runs.py +0 -0
  210. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_cli_setup.py +0 -0
  211. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_config.py +0 -0
  212. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_example_validation_contract.py +0 -0
  213. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_harbor_scaffold_runner.py +0 -0
  214. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_model_auth.py +0 -0
  215. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_profile_config.py +0 -0
  216. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_scaffold_runner.py +0 -0
  217. {castform-0.2.3 → castform-0.2.4}/tests/unit/test_validation.py +0 -0
  218. {castform-0.2.3 → castform-0.2.4}/tests/unit/traces/test_adapter.py +0 -0
  219. {castform-0.2.3 → castform-0.2.4}/tests/unit/traces/test_braintrust_adapter.py +0 -0
  220. {castform-0.2.3 → castform-0.2.4}/tests/unit/traces/test_braintrust_extraction.py +0 -0
  221. {castform-0.2.3 → castform-0.2.4}/tests/unit/traces/test_http.py +0 -0
  222. {castform-0.2.3 → castform-0.2.4}/tests/unit/traces/test_pivot.py +0 -0
  223. {castform-0.2.3 → castform-0.2.4}/tests/unit/traces/test_processing.py +0 -0
  224. {castform-0.2.3 → castform-0.2.4}/tests/unit/traces/test_registry.py +0 -0
@@ -1,12 +1,12 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: castform
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: SDK and CLI for the Castform training platform
5
5
  Author: castie@castform.com
6
6
  Classifier: Operating System :: OS Independent
7
7
  Classifier: Programming Language :: Python :: 3
8
8
  Requires-Python: ==3.12.*
9
- Requires-Dist: benchmax==0.2.3
9
+ Requires-Dist: benchmax==0.2.4
10
10
  Requires-Dist: httpx[http2]>=0.27.0
11
11
  Requires-Dist: tqdm>=4.66.0
12
12
  Provides-Extra: chroma
@@ -1,12 +1,12 @@
1
1
  [project]
2
2
  name = "castform"
3
- version = "0.2.3"
3
+ version = "0.2.4"
4
4
  description = "SDK and CLI for the Castform training platform"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "castie@castform.com" }]
7
7
  requires-python = "==3.12.*"
8
8
  dependencies = [
9
- "benchmax==0.2.3",
9
+ "benchmax==0.2.4",
10
10
  "httpx[http2]>=0.27.0",
11
11
  "tqdm>=4.66.0",
12
12
  ]
@@ -26,6 +26,12 @@ Before changing a stage, load its skill:
26
26
  | validation and baseline review | `.claude/skills/verify-environment/SKILL.md` |
27
27
  | bundle, upload and launch | `.claude/skills/launch-run/SKILL.md` |
28
28
  | status, curves, rollouts and logs | `.claude/skills/view-progress/SKILL.md` |
29
+ | supervised finetuning from labeled data | `.claude/skills/train-sft/SKILL.md` |
30
+
31
+ If the user already has the completions the model should imitate (labeled
32
+ conversations, transcripts, input→output pairs), that is **supervised
33
+ finetuning** — read the `train-sft` skill and skip the RL loop above entirely:
34
+ SFT has no environment, validate stage, or rewards.
29
35
 
30
36
  ## Project contract
31
37
 
@@ -0,0 +1,141 @@
1
+ ---
2
+ name: train-sft
3
+ description: Build a validated benchmax-sft-v1 dataset from existing labeled conversations, upload it, and explicitly launch a supervised finetuning run — no environment, rewards, or rollouts.
4
+ ---
5
+
6
+ # Train with SFT
7
+
8
+ Use this when the user **already has the completions they want the model to
9
+ imitate** — support transcripts, labeled chat data, tool-call traces, input→output
10
+ pairs. There is no environment, tool loop, reward, or validate stage: the RL loop
11
+ in this project's other skills does not apply. If the task needs the model to
12
+ *discover* good behavior against a scorer, use the RL skills instead.
13
+
14
+ ## The whole flow
15
+
16
+ ```python
17
+ from benchmax.sft import SftDataset, SftDatasetError
18
+ from castform.platform import SftTrainingConfig, TrainerClient, upload_sft_assets
19
+
20
+ train = SftDataset.from_jsonl("train.jsonl") # or SftDataset.from_rows(rows)
21
+ uploaded = upload_sft_assets(dataset=train, run_name="support-sft")
22
+ run_id = TrainerClient().launch_sft_run(
23
+ assets=uploaded,
24
+ name="support-sft",
25
+ config=SftTrainingConfig(num_epochs=1, learning_rate=1e-5, seed=42),
26
+ )
27
+ ```
28
+
29
+ Construction is **all-or-nothing**: `SftDataset` either satisfies the whole
30
+ `benchmax-sft-v1` contract or raises `SftDatasetError` with every issue, ordered
31
+ and line-aware. Fix the data the diagnostics point at — never pre-filter rows
32
+ silently or patch around individual issues without telling the user.
33
+
34
+ ## Row contract (one JSON object per line)
35
+
36
+ ```json
37
+ {
38
+ "messages": [
39
+ {"role": "user", "content": "What is 2 + 2?"},
40
+ {"role": "assistant", "content": "4", "weight": 1}
41
+ ],
42
+ "tools": [],
43
+ "metadata": {"id": "optional producer identity"}
44
+ }
45
+ ```
46
+
47
+ - `system`/`user`: exactly `role` + non-empty string `content`.
48
+ - `assistant`: optional string-or-null `content`, optional non-empty
49
+ `tool_calls`, optional integer `weight` `0 | 1` (omitted means `1`). Each
50
+ assistant turn needs content or a tool call; each row needs at least one
51
+ assistant turn with effective weight `1`.
52
+ - `tool` results: exactly `role` + string `content` + non-empty `tool_call_id`;
53
+ every tool call gets exactly one result, in declaration order, before the
54
+ next non-tool message. Tool definitions are OpenAI function shapes;
55
+ `function.arguments` must decode as a JSON object.
56
+ - Everything else is rejected: images/audio/multimodal parts, fractional
57
+ weights, legacy prompt/completion keys, unknown fields, duplicate JSON keys,
58
+ rows over 1 MiB, more than 1024 messages.
59
+
60
+ **Masking:** set `weight: 0` on assistant turns that are context, not target
61
+ (earlier drafts, retrieved answers, another model's output). Only weight-1
62
+ turns contribute to the loss.
63
+
64
+ ## What the user actually chooses
65
+
66
+ | arg | accepted | default |
67
+ |---|---|---|
68
+ | `num_epochs` | 1–100 | 1 |
69
+ | `learning_rate` | (0, 0.1] | 1e-5 |
70
+ | `max_context_tokens` | 256–8192, or 32768 / 65536 / 131072 (long context — must be enabled on the platform) | 8192 |
71
+ | `save_interval` (steps) | 1–10000 | 20 |
72
+ | `seed` | 0–2147483647 | 42 |
73
+ | `lr_decay_style` | `"constant"` or `"cosine"` | unset — keeps the platform default |
74
+ | `min_lr` | ≥ 0 and below `learning_rate` | unset |
75
+ | `warmup_ratio` | 0–0.5 of total steps | unset |
76
+ | `adam_beta2` | 0.9–0.999 | unset |
77
+ | `grad_clip` | (0, 10] | unset |
78
+ | `lora_rank` | 32 or 64 | unset — keeps the platform's fixed policy |
79
+ | `global_batch_size` | 4–64, multiple of 4 at `max_context_tokens` ≤ 8192; 1–64 at a long-context rung (the platform picks the topology, so it decides divisibility) | unset — 4 |
80
+ | `eval_interval` (steps) | 1–10000; only with an eval set | unset — derived from `save_interval` |
81
+
82
+ Every arg whose default reads `unset` is optional: leave it out and the
83
+ platform's own value applies, so an untouched config behaves exactly as before
84
+ these knobs existed. Do not set one just to restate a default.
85
+
86
+ `lora_rank` picks the adapter's rank; alpha is always derived as 2x and is not
87
+ a knob. Rank 128 is not accepted — it trains, but serving cannot load it.
88
+
89
+ Model (`Qwen/Qwen3.5-4B`) and GPU topology are platform-owned — do not invent
90
+ knobs for them. A row that renders past `max_context_tokens` tokens fails the
91
+ run's preflight; trim long rows up front.
92
+
93
+ ## Held-out eval (optional)
94
+
95
+ Pass a second dataset to score during training:
96
+
97
+ ```python
98
+ assets = upload_sft_assets(dataset=train, eval_dataset=held_out, run_name="...")
99
+ ```
100
+
101
+ The eval set is scored on the live weights between training steps and plotted
102
+ as `eval/loss` beside `train/loss`. Rules worth knowing before you offer it:
103
+
104
+ - **At most 2048 rows**, under the same per-row limits as training rows. The
105
+ bound is a compute bound, not a taste one — eval runs on the training GPUs
106
+ and pauses training while it does.
107
+ - **It is never billed.** Eval forward passes cost the user nothing, which is
108
+ also why the size and cadence are capped rather than left open.
109
+ - **Cadence defaults to `save_interval`**, so by default every eval lands on a
110
+ checkpoint. Set `eval_interval` only to make it sparser; a much denser
111
+ cadence is rejected at launch.
112
+ - An eval set is part of the data identity: changing it produces a different
113
+ upload prefix, and a resumed run must keep the one it started with.
114
+
115
+ Skip it for small or exploratory runs — a held-out split costs training rows,
116
+ and `train/loss` alone answers "is this learning at all".
117
+
118
+ ## Cost and consent
119
+
120
+ `launch_sft_run` spends GPU credits. Ask the human before calling it, every
121
+ time — preparing and uploading the dataset first is free and fine. Steps per
122
+ epoch ≈ rows / 4 (tiny datasets pad by repeating their first rows, so 1–3-row
123
+ datasets train on repeats; prefer at least a few dozen rows). Stopping a run
124
+ keeps only checkpoints already uploaded; work since the last one is lost.
125
+
126
+ If launch fails with "SFT launch is not enabled", the platform gate is off for
127
+ this account — surface that to the user rather than retrying.
128
+
129
+ ## Monitor
130
+
131
+ Same as any run (`view-progress` skill): `castform runs status <id>`, and
132
+ `castform runs scalars <id>` — watch `train/loss` fall, and `eval/loss` too
133
+ when the run has an eval set. There are no rollouts or reward curves for SFT
134
+ runs. The run page shows loss, dataset prefix, and config; runs with an eval
135
+ set also get an eval tab, chart-only.
136
+
137
+ ## Reference
138
+
139
+ The canonical worked example (streaming a pinned public corpus, bounded
140
+ mapping, offline tests, explicit paid `--launch` gate) ships in the benchmax
141
+ repo under `examples/sft/pii_masking/`.
@@ -38,6 +38,7 @@ _SKILLS = (
38
38
  "verify-environment",
39
39
  "launch-run",
40
40
  "view-progress",
41
+ "train-sft",
41
42
  )
42
43
 
43
44
  # Where each agent looks for the per-stage skills. Claude Code auto-loads
@@ -8,17 +8,21 @@ from .environment_assets import UploadedEnvironmentAssets, upload_assets
8
8
  # Imported last: login depends on credentials/device_auth (siblings), so this
9
9
  # stays cycle-free as long as those are already loaded by the imports above.
10
10
  from .login import ensure_session
11
+ from .sft import SftTrainingConfig, UploadedSftAssets, upload_sft_assets
11
12
 
12
13
  __all__ = [
13
14
  "RolloutClient",
14
15
  "PlatformConfig",
16
+ "SftTrainingConfig",
15
17
  "StorageClient",
16
18
  "TrainerClient",
17
19
  "UploadedEnvironmentAssets",
20
+ "UploadedSftAssets",
18
21
  # The seam token-getter: generated scripts pass it to a raw OpenAI client
19
22
  # (e.g. the traces pivot), so it's part of the public surface alongside
20
23
  # ensure_session — not just an internal credentials helper.
21
24
  "platform_bearer",
22
25
  "ensure_session",
23
26
  "upload_assets",
27
+ "upload_sft_assets",
24
28
  ]
@@ -9,10 +9,15 @@ import warnings
9
9
  from collections.abc import Iterator, Mapping
10
10
  from dataclasses import dataclass, field
11
11
  from pathlib import Path
12
- from typing import Any
12
+ from typing import TYPE_CHECKING, Any
13
13
 
14
14
  import httpx
15
15
 
16
+ if TYPE_CHECKING:
17
+ # Runtime import stays inside launch_sft_run: sft.py imports this module
18
+ # for StorageClient, so a top-level import would be circular.
19
+ from .sft import SftTrainingConfig, UploadedSftAssets
20
+
16
21
  from castform import config
17
22
 
18
23
  from .credentials import TokenProvider, resolve_token_provider
@@ -421,6 +426,82 @@ class TrainerClient:
421
426
  warnings.warn(f"launch warning: {warning}", stacklevel=2)
422
427
  return body["runId"]
423
428
 
429
+ def launch_sft_run(
430
+ self,
431
+ *,
432
+ assets: UploadedSftAssets,
433
+ name: str,
434
+ config: SftTrainingConfig | None = None,
435
+ ) -> str:
436
+ """Launch an env-less SFT run through the dedicated SFT endpoint.
437
+
438
+ Only the typed uploaded reference and the genuine v1 choices cross the
439
+ wire; the platform owns the model, LoRA policy, topology, and
440
+ scheduling. No environment paths, secrets, or template selectors are
441
+ accepted or synthesized.
442
+
443
+ Args:
444
+ assets: Result of ``upload_sft_assets`` — the dataset prefix plus
445
+ its literal format identifier.
446
+ name: Run name (same safe-name limits as RL runs).
447
+ config: The v1 training choices; defaults to
448
+ ``SftTrainingConfig()``.
449
+
450
+ Returns:
451
+ The training run ID.
452
+
453
+ Raises:
454
+ AuthenticationError: If the bearer is invalid.
455
+ JobLaunchError: If the platform rejects or fails the launch,
456
+ including when SFT launch is disabled.
457
+ """
458
+
459
+ from .sft import SftTrainingConfig, UploadedSftAssets
460
+
461
+ if not isinstance(assets, UploadedSftAssets):
462
+ raise TypeError(
463
+ f"assets must be an UploadedSftAssets from upload_sft_assets, "
464
+ f"got {type(assets).__name__}"
465
+ )
466
+ resolved = config if config is not None else SftTrainingConfig()
467
+ if not isinstance(resolved, SftTrainingConfig):
468
+ raise TypeError(f"config must be an SftTrainingConfig, got {type(config).__name__}")
469
+ dataset: dict[str, Any] = {
470
+ "format": assets.dataset_format,
471
+ "path": assets.dataset_path,
472
+ }
473
+ body: dict[str, Any] = {
474
+ "name": name,
475
+ "dataset": dataset,
476
+ "args": resolved.as_args(),
477
+ }
478
+
479
+ # The MARKER turns eval on and rides the uploaded assets, not the
480
+ # config: no eval.jsonl in the prefix, no eval. Train identity is sent
481
+ # only alongside the marker, since the platform needs it to derive the
482
+ # pass cap and re-derive the prefix.
483
+ if assets.eval_digest is not None and assets.eval_row_count is not None:
484
+ if assets.row_count is None:
485
+ raise ValueError(
486
+ "assets carry an eval set but no train row_count; re-upload with "
487
+ "upload_sft_assets so the launch can be range-checked"
488
+ )
489
+ dataset["digest"] = assets.content_digest
490
+ dataset["rows"] = assets.row_count
491
+ body["eval"] = {
492
+ "rows": assets.eval_row_count,
493
+ "digest": assets.eval_digest,
494
+ }
495
+ elif resolved.eval_interval is not None:
496
+ raise ValueError(
497
+ "eval_interval was set but the uploaded assets carry no eval set; "
498
+ "pass eval_dataset=... to upload_sft_assets or drop eval_interval"
499
+ )
500
+
501
+ response = self._http_client.post("/v1/train/runs/sft", json=body)
502
+ self._handle_response_errors(response)
503
+ return response.json()["runId"]
504
+
424
505
  def list_launch_args(self) -> list[LaunchArgSpec]:
425
506
  """Fetch the schema of launch args this platform accepts.
426
507
 
@@ -0,0 +1,363 @@
1
+ """Typed SFT dataset upload and launch transport.
2
+
3
+ Separate from environment-bundle uploads on purpose: SFT has no environment,
4
+ so this surface accepts only a fully validated
5
+ :class:`benchmax.sft.SftDataset` and never optionalizes bundle fields. The
6
+ platform owns the fixed model/LoRA/topology policy; only the genuine v1
7
+ choices appear in :class:`SftTrainingConfig`.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import hashlib
13
+ import math
14
+ from dataclasses import dataclass
15
+
16
+ from benchmax.sft import SFT_DATASET_FORMAT, SftDataset
17
+
18
+ from castform import config
19
+
20
+ from .client import StorageClient
21
+ from .environment_assets import _validate_blob_path
22
+
23
+ __all__ = [
24
+ "MAX_EVAL_ROWS",
25
+ "SftTrainingConfig",
26
+ "UploadedSftAssets",
27
+ "sft_assets_digest",
28
+ "upload_sft_assets",
29
+ ]
30
+
31
+ _LR_DECAY_STYLES = frozenset({"constant", "cosine"})
32
+
33
+ # Rank 128 trains but fused QKV expands it past serving MAX_LORA_RANK caps, so
34
+ # it stays platform-only; these mirror the server's public set.
35
+ _PUBLIC_LORA_RANKS = frozenset({32, 64})
36
+
37
+ # Megatron needs global_batch_size divisible by the data-parallel width, which
38
+ # is 4 on the fixed SFT topology. Mirrors the server; the server is authority.
39
+ _DATA_PARALLEL_SIZE = 4
40
+
41
+ # Context sizing. At or below the v1 ceiling any value is accepted; above it,
42
+ # only the frozen ladder rungs exist. Mirrors the server's shape.
43
+ #
44
+ # The server-side flag that gates long context is deliberately NOT modelled
45
+ # here. A flag-off platform rejects anything above 8192 whatever the SDK
46
+ # version, so mirroring the flag would only let this client go stale against a
47
+ # value it cannot observe. This range says which values are WELL-FORMED, not
48
+ # which are currently enabled.
49
+ V1_MAX_CONTEXT_TOKENS = 8192
50
+ MIN_CONTEXT_TOKENS = 256
51
+ LONG_CONTEXT_LADDER = (32768, 65536, 131072)
52
+
53
+ # Eval rows the platform accepts. Mirrored here so an oversized set fails
54
+ # before the upload rather than at launch; the server is the authority and
55
+ # re-counts the real bytes.
56
+ MAX_EVAL_ROWS = 2048
57
+
58
+
59
+ @dataclass(frozen=True)
60
+ class UploadedSftAssets:
61
+ """Immutable reference to one uploaded SFT dataset prefix.
62
+
63
+ ``dataset_path`` is the blob prefix holding ``train.jsonl``;
64
+ ``dataset_format`` is the literal public format identifier; and
65
+ ``content_digest`` is the full SHA-256 hex digest of the canonical JSONL
66
+ bytes. Pass the whole object to ``TrainerClient.launch_sft_run``.
67
+
68
+ The eval fields are set only when ``upload_sft_assets`` received an
69
+ ``eval_dataset``; their presence is what makes the launch send the eval
70
+ marker, so an ``eval.jsonl`` that merely exists at the prefix stays inert.
71
+ """
72
+
73
+ dataset_path: str
74
+ dataset_format: str
75
+ content_digest: str
76
+ row_count: int | None = None
77
+ eval_digest: str | None = None
78
+ eval_row_count: int | None = None
79
+
80
+
81
+ @dataclass(frozen=True)
82
+ class SftTrainingConfig:
83
+ """The genuine caller choices for a v1 SFT run.
84
+
85
+ Everything else — model, LoRA rank/alpha, batch size, GPU topology,
86
+ optimizer, checkpoint layout, stop policy — is platform-owned and not
87
+ accepted here. Ranges mirror the platform's public argument table so bad
88
+ values fail before any request; the server remains authoritative.
89
+ """
90
+
91
+ num_epochs: int = 1
92
+ learning_rate: float = 1e-5
93
+ max_context_tokens: int = 8192
94
+ save_interval: int = 20
95
+ seed: int = 42
96
+ # Optional knobs. ``None`` means "not sent": the field is omitted from
97
+ # ``as_args()``, so the platform stamps nothing and the trainer keeps the
98
+ # model config's value.
99
+ lr_decay_style: str | None = None
100
+ min_lr: float | None = None
101
+ warmup_ratio: float | None = None
102
+ adam_beta2: float | None = None
103
+ grad_clip: float | None = None
104
+ lora_rank: int | None = None
105
+ global_batch_size: int | None = None
106
+ # Only meaningful with an eval set: the launch rejects an interval sent
107
+ # without the eval marker rather than silently ignoring it. Unset means the
108
+ # platform derives the cadence from save_interval.
109
+ eval_interval: int | None = None
110
+
111
+ def __post_init__(self) -> None:
112
+ self._require_int("num_epochs", self.num_epochs, 1, 100)
113
+ rate = self.learning_rate
114
+ if isinstance(rate, bool) or not isinstance(rate, int | float):
115
+ raise ValueError("learning_rate must be a number")
116
+ if not math.isfinite(rate) or rate <= 0 or rate > 0.1:
117
+ raise ValueError("learning_rate must be finite, greater than 0, and at most 0.1")
118
+ self._require_context_tokens(self.max_context_tokens)
119
+ self._require_int("save_interval", self.save_interval, 1, 10_000)
120
+ self._require_int("seed", self.seed, 0, 2_147_483_647)
121
+
122
+ if self.lr_decay_style is not None and self.lr_decay_style not in _LR_DECAY_STYLES:
123
+ raise ValueError(f"lr_decay_style must be one of {', '.join(sorted(_LR_DECAY_STYLES))}")
124
+ self._require_optional_number("min_lr", self.min_lr, 0.0, None)
125
+ if self.min_lr is not None and self.min_lr >= rate:
126
+ raise ValueError("min_lr must be less than learning_rate")
127
+ self._require_optional_number("warmup_ratio", self.warmup_ratio, 0.0, 0.5)
128
+ self._require_optional_number("adam_beta2", self.adam_beta2, 0.9, 0.999)
129
+ self._require_optional_number(
130
+ "grad_clip", self.grad_clip, None, 10.0, exclusive_minimum=0.0
131
+ )
132
+ if self.lora_rank is not None and self.lora_rank not in _PUBLIC_LORA_RANKS:
133
+ raise ValueError(
134
+ f"lora_rank must be one of {', '.join(str(r) for r in sorted(_PUBLIC_LORA_RANKS))}"
135
+ )
136
+ if self.global_batch_size is not None:
137
+ # The divisibility rule depends on the data-parallel width, and DP
138
+ # depends on the context-parallel size the SERVER resolves from the
139
+ # context bucket. In the v1 range CP is always 1, so DP is always 4
140
+ # and the rule is knowable here. Above the v1 ceiling it is not:
141
+ # the platform picks CP per rung, DP narrows to 2 or 1, and batch
142
+ # sizes this client would reject become legal.
143
+ #
144
+ # Rather than mirror the context->CP table — which would let this
145
+ # client go stale against a server-owned mapping, exactly the
146
+ # split-brain that has already cost this project two paid launches
147
+ # — only the range is enforced above the ceiling and the server
148
+ # decides divisibility.
149
+ in_v1_range = (
150
+ isinstance(self.max_context_tokens, int)
151
+ and not isinstance(self.max_context_tokens, bool)
152
+ and self.max_context_tokens <= V1_MAX_CONTEXT_TOKENS
153
+ )
154
+ minimum = _DATA_PARALLEL_SIZE if in_v1_range else 1
155
+ self._require_int("global_batch_size", self.global_batch_size, minimum, 64)
156
+ if in_v1_range and self.global_batch_size % _DATA_PARALLEL_SIZE:
157
+ raise ValueError(
158
+ f"global_batch_size must be a multiple of {_DATA_PARALLEL_SIZE} "
159
+ "(the data-parallel width of the fixed SFT topology)"
160
+ )
161
+
162
+ @staticmethod
163
+ def _require_int(name: str, value: object, minimum: int, maximum: int) -> None:
164
+ if isinstance(value, bool) or not isinstance(value, int):
165
+ raise ValueError(f"{name} must be an integer")
166
+ if not minimum <= value <= maximum:
167
+ raise ValueError(f"{name} must be between {minimum} and {maximum}")
168
+
169
+ @staticmethod
170
+ def _require_context_tokens(value: object) -> None:
171
+ """Free range up to the v1 ceiling, frozen ladder rungs above it.
172
+
173
+ Two shapes rather than one range because that is what the server
174
+ enforces: below the ceiling every value has been runnable since v1,
175
+ while above it only the rungs with measured calibration evidence exist
176
+ — an arbitrary 40000 is refused there, not clamped.
177
+
178
+ Whether a rung is currently ENABLED is a server-side flag this client
179
+ deliberately does not model, so a well-formed value here can still be
180
+ refused at launch. That is the intended split: the SDK rejects what can
181
+ never work, the platform decides what works today.
182
+ """
183
+ if isinstance(value, bool) or not isinstance(value, int):
184
+ raise ValueError("max_context_tokens must be an integer")
185
+ if MIN_CONTEXT_TOKENS <= value <= V1_MAX_CONTEXT_TOKENS:
186
+ return
187
+ if value in LONG_CONTEXT_LADDER:
188
+ return
189
+ raise ValueError(
190
+ f"max_context_tokens must be between {MIN_CONTEXT_TOKENS} and "
191
+ f"{V1_MAX_CONTEXT_TOKENS}, or one of "
192
+ f"{', '.join(str(v) for v in LONG_CONTEXT_LADDER)} "
193
+ f"(long context must be enabled on the platform for those)"
194
+ )
195
+
196
+ @staticmethod
197
+ def _require_optional_number(
198
+ name: str,
199
+ value: object,
200
+ minimum: float | None,
201
+ maximum: float | None,
202
+ *,
203
+ exclusive_minimum: float | None = None,
204
+ ) -> None:
205
+ """Range-check an optional knob, leaving ``None`` (not sent) untouched."""
206
+
207
+ if value is None:
208
+ return
209
+ if isinstance(value, bool) or not isinstance(value, int | float):
210
+ raise ValueError(f"{name} must be a number")
211
+ if not math.isfinite(value):
212
+ raise ValueError(f"{name} must be finite")
213
+ if minimum is not None and value < minimum:
214
+ raise ValueError(f"{name} must be at least {minimum}")
215
+ if exclusive_minimum is not None and value <= exclusive_minimum:
216
+ raise ValueError(f"{name} must be greater than {exclusive_minimum}")
217
+ if maximum is not None and value > maximum:
218
+ raise ValueError(f"{name} must be at most {maximum}")
219
+
220
+ def as_args(self) -> dict[str, int | float | str]:
221
+ """The resolved public ``args`` object for the SFT launch request.
222
+
223
+ Unset knobs are omitted rather than serialized as null: the platform
224
+ reads presence, so a null would read as a deliberate override.
225
+ """
226
+
227
+ args: dict[str, int | float | str] = {
228
+ "num_epochs": self.num_epochs,
229
+ "learning_rate": self.learning_rate,
230
+ "max_context_tokens": self.max_context_tokens,
231
+ "save_interval": self.save_interval,
232
+ "seed": self.seed,
233
+ }
234
+ for name in (
235
+ "lr_decay_style",
236
+ "min_lr",
237
+ "warmup_ratio",
238
+ "adam_beta2",
239
+ "grad_clip",
240
+ "lora_rank",
241
+ "global_batch_size",
242
+ "eval_interval",
243
+ ):
244
+ value = getattr(self, name)
245
+ if value is not None:
246
+ args[name] = value
247
+ return args
248
+
249
+
250
+ def sft_assets_digest(train_digest: str, eval_digest: str | None = None) -> str:
251
+ """The identity digest for a launch's full asset set.
252
+
253
+ With no eval set this is the train digest, which keeps every previously
254
+ uploaded prefix byte-stable. With one it is a domain-separated hash over
255
+ fixed-width raw component digests::
256
+
257
+ sha256(b"castform-sft-assets-v1\\0" + b"train\\0" + raw32(train)
258
+ + b"eval\\0" + raw32(eval))
259
+
260
+ Tags and fixed-width components make the framing unambiguous; hashing the
261
+ raw payloads concatenated would not be, so a prefix would stop pinning
262
+ which bytes were which. Because the eval digest feeds the prefix, adding
263
+ or changing an eval set produces a NEW prefix — an overwrite at the old
264
+ one cannot swap eval sets under a launched run.
265
+
266
+ The platform re-derives this and rejects a prefix that disagrees, so this
267
+ construction must stay byte-identical to
268
+ ``platform-service/src/lib/sft-eval-assets.ts``.
269
+ """
270
+ if eval_digest is None:
271
+ return train_digest
272
+ hasher = hashlib.sha256()
273
+ hasher.update(b"castform-sft-assets-v1\0")
274
+ hasher.update(b"train\0")
275
+ hasher.update(bytes.fromhex(train_digest))
276
+ hasher.update(b"eval\0")
277
+ hasher.update(bytes.fromhex(eval_digest))
278
+ return hasher.hexdigest()
279
+
280
+
281
+ def upload_sft_assets(
282
+ *,
283
+ dataset: SftDataset,
284
+ run_name: str,
285
+ eval_dataset: SftDataset | None = None,
286
+ api_key: str | None = None,
287
+ base_url: str | None = None,
288
+ storage_client: StorageClient | None = None,
289
+ ) -> UploadedSftAssets:
290
+ """Upload a validated SFT dataset, and optionally an eval set beside it.
291
+
292
+ The blob layout is content-addressed like RL datasets:
293
+ ``datasets/<run_name>/<digest16>/train.jsonl`` where ``digest16`` is the
294
+ first 16 hex chars of :func:`sft_assets_digest` — the train digest alone
295
+ when there is no eval set, so train-only prefixes are unchanged. An eval set is
296
+ written to ``eval.jsonl`` under the same prefix. Auth, retry, and
297
+ path-safety ride the same :class:`StorageClient` mechanism as RL uploads.
298
+
299
+ Args:
300
+ dataset: A fully constructed :class:`benchmax.sft.SftDataset`. Invalid
301
+ data cannot reach here — construction already failed loudly.
302
+ run_name: Asset namespace; must satisfy the platform blob-path charset.
303
+ eval_dataset: Optional held-out set to score during training.
304
+ api_key: Platform API key; omitted means the per-request credential
305
+ seam resolves the bearer.
306
+ base_url: Platform base URL. Defaults to ``config.platform_url()``.
307
+ storage_client: BYOC for connection reuse or test fakes.
308
+
309
+ Returns:
310
+ UploadedSftAssets carrying the prefix, literal format, both digests,
311
+ and both row counts.
312
+
313
+ Raises:
314
+ ValueError: If the eval set exceeds :data:`MAX_EVAL_ROWS`. A local
315
+ mirror of the platform's bound — a convenience, never the
316
+ enforcement point.
317
+ """
318
+
319
+ if not isinstance(dataset, SftDataset):
320
+ raise TypeError(
321
+ f"dataset must be a benchmax.sft.SftDataset, got {type(dataset).__name__}; "
322
+ "construct one with SftDataset.from_jsonl(...) or SftDataset.from_rows(...)"
323
+ )
324
+ if eval_dataset is not None and not isinstance(eval_dataset, SftDataset):
325
+ raise TypeError(
326
+ f"eval_dataset must be a benchmax.sft.SftDataset, got {type(eval_dataset).__name__}"
327
+ )
328
+
329
+ payload = dataset.to_jsonl_bytes()
330
+ digest = hashlib.sha256(payload).hexdigest()
331
+
332
+ eval_payload: bytes | None = None
333
+ eval_digest: str | None = None
334
+ eval_row_count: int | None = None
335
+ if eval_dataset is not None:
336
+ if len(eval_dataset.rows) > MAX_EVAL_ROWS:
337
+ raise ValueError(
338
+ f"eval_dataset has {len(eval_dataset.rows)} rows, "
339
+ f"above the {MAX_EVAL_ROWS}-row limit"
340
+ )
341
+ eval_payload = eval_dataset.to_jsonl_bytes()
342
+ eval_digest = hashlib.sha256(eval_payload).hexdigest()
343
+ eval_row_count = len(eval_dataset.rows)
344
+
345
+ prefix = f"datasets/{run_name}/{sft_assets_digest(digest, eval_digest)[:16]}"
346
+ _validate_blob_path(prefix, source="run_name")
347
+
348
+ if storage_client is None:
349
+ storage_client = StorageClient(
350
+ api_key=api_key,
351
+ base_url=base_url or config.platform_url(),
352
+ )
353
+ storage_client.upload_file(f"{prefix}/train.jsonl", payload, "application/jsonl")
354
+ if eval_payload is not None:
355
+ storage_client.upload_file(f"{prefix}/eval.jsonl", eval_payload, "application/jsonl")
356
+ return UploadedSftAssets(
357
+ dataset_path=prefix,
358
+ dataset_format=SFT_DATASET_FORMAT,
359
+ content_digest=digest,
360
+ row_count=len(dataset.rows),
361
+ eval_digest=eval_digest,
362
+ eval_row_count=eval_row_count,
363
+ )