मुख्य सामग्री पर जाएं
प्रशिक्षण मार्गदर्शिका के अध्याय सभी दस्तावेज़

Python SDK: तरीके, नतीजे और त्रुटियाँ

TrainingProject के method signature, arguments, नतीजों के अनुबंध और संभाली जा सकने वाली विफलताएँ, पूरे Python उदाहरणों सहित।

प्रशिक्षण मार्गदर्शिका के अध्याय

हर भाषा में कमांड और कोड अंग्रेज़ी में ही रहेंगे। बड़े अक्षरों वाले प्लेसहोल्डर को अपने खाते और भुगतान किए गए कार्य के मानों से बदलें; साझा नोटबुक या लॉग में असली कुंजियाँ न डालें।

एक प्रोजेक्ट API, एक ही मूल इंजन

CLI और Python में कॉन्फ़िगरेशन, स्थिति और आउटपुट एक जैसे होने चाहिए।
  1. from_file भार बदले बिना लोड करें
  2. plan तय इनपुट जाँचें
  3. run / नियंत्रण वर्कर और रिकवरी संभालें
  4. evaluate / export स्वीकृत स्थानीय नतीजे देखें

from_file: भार बदले बिना लोड करें. plan: तय इनपुट जाँचें. run / नियंत्रण: वर्कर और रिकवरी संभालें. evaluate / export: स्वीकृत स्थानीय नतीजे देखें

Python से वही इंजन इस्तेमाल करें

TrainingProject, TrainingClient का विकल्प नहीं, उसका पूरक है। कॉन्फ़िगरेशन और सीमित अधिकारों वाली API key लोड करें, योजना देखें और फिर रन शुरू करें। प्रोजेक्ट ऑब्जेक्ट अपने रन को देखने और नियंत्रित करने देता है; run मौजूदा रन को नहीं लिखता और resume के लिए मान्य रिकवरी स्थिति चाहिए।

  • पथ string या os.PathLike हो सकते हैं। विधि के विकल्प केवल नाम वाले तर्कों के रूप में दिए जाते हैं।
  • from_file स्थानीय कॉन्फ़िगरेशन जाँचता है; यह भार नहीं बदलता और शिक्षक को अनुरोध नहीं भेजता।
  • Python और CLI में एक जैसी सेटिंग, फ़िंगरप्रिंट, बजट और आउटपुट इस्तेमाल होते हैं।
Python प्रोजेक्ट का पूरा संदर्भ
फ़ील्ड या इंटरफ़ेसप्रकार या परिणामडिफ़ॉल्ट या एग्ज़िट कोडव्यवहार और सत्यापन
TrainingProject.from_file(path, *, api_key) TrainingProject अनिवार्य / कोई डिफ़ॉल्ट नहीं कॉन्फ़िगरेशन का पथ और खाली न हो ऐसी सीक्रेट स्ट्रिंग लोड करके जाँचें। प्रोजेक्ट ऑब्जेक्ट लौटता है; भार नहीं बदलता और शिक्षक को अनुरोध नहीं भेजता।
plan(*, dry_run=True) dict true केवल True। resolved_configuration, compatibility, data_sharing, budgets, topics, artifacts और fingerprints लौटाता है।
run() dict अनिवार्य / कोई डिफ़ॉल्ट नहीं अंतिम या रुकी हुई स्थिति तक प्रतीक्षा करें; कार्रवाई सफल हो तभी साझा रन-नतीजा लौटाएँ, वरना संबंधित त्रुटि दें।
status() dict अनिवार्य / कोई डिफ़ॉल्ट नहीं कार्यकर्ता शुरू किए बिना run_id, status, stop_reason, report_path और unmet_criteria पढ़ें।
pause() dict अनिवार्य / कोई डिफ़ॉल्ट नहीं कार्यकर्ता की पुष्टि और मान्य चेकपॉइंट की प्रतीक्षा करें; साझा रन-नतीजा लौटाएँ। अमान्य स्थिति पर कॉन्फ़िगरेशन त्रुटि आती है।
resume() dict अनिवार्य / कोई डिफ़ॉल्ट नहीं सभी फ़िंगरप्रिंट जाँचकर अपने कार्यकर्ता फिर शुरू करें; कार्रवाई सफल होने पर साझा रन-नतीजा लौटाएँ।
cancel() dict अनिवार्य / कोई डिफ़ॉल्ट नहीं अपने कार्यकर्ता रुकने की प्रतीक्षा करके रद्द स्थिति लौटाएँ; सुरक्षित रूप से रुकने की पुष्टि न हो तो CancellationError दें।
evaluate(*, split="test") dict "test" validation या test स्वीकार करें। run_id, split, accepted, criteria, regressions और report_path लौटाएँ; स्वीकृति विफल हो तो रिपोर्ट सहेजकर EvaluationFailedError दें।
export(*, format="safetensors") dict "safetensors" स्वीकृत, संगत सामग्री के लिए run_id, format, artifact_path, manifest_path और sha256 लौटाएँ।
register_evaluator(name, scorer, *, version) None अनिवार्य / कोई डिफ़ॉल्ट नहीं प्लान बनाने या मूल्यांकन से पहले भरोसेमंद स्कोरिंग फ़ंक्शन रजिस्टर करें। स्थिर नाम और स्पष्ट संस्करण दें। फ़ंक्शन को prediction, target और row मिलते हैं और उसे 0 से 1 के बीच सीमित संख्या लौटानी चाहिए। पहले से मौजूद मेट्रिक बदले नहीं जा सकते।
उदाहरण · python
import os
from fusionpointai_training import TrainingProject

project = TrainingProject.from_file(
    "./german-project/training.json",
    api_key=os.environ["FUSIONPOINTAI_API_KEY"],
)
plan = project.plan(dry_run=True)
print(plan["resolved_configuration"], plan["data_sharing"], plan["budgets"])
# Confirm the reviewed plan before starting real work.
result = project.run()
if result["status"] != "completed" or result["stop_reason"] != "accepted":
    raise RuntimeError("Training was not accepted; inspect the retained report.")
evaluation = project.evaluate(split="test")
# A failed required criterion raises EvaluationFailedError after saving its report.
artifact = project.export(format="safetensors")
print(artifact["manifest_path"])

नतीजों की संरचना देखें

नीचे नतीजों का प्रारूप दिया है, नमूने के माप नहीं। तैनाती से पहले status, stop_reason और unmet_criteria देखें। मूल्यांकन में हर कसौटी और गिरावट का हिसाब मिलता है। एक्सपोर्ट स्थानीय पथ और फ़ाइल की अखंडता की जानकारी देता है; यह न मॉडल अपलोड करता है, न उत्पादन की अनुमान सेवा बदलता है।

  • स्थिति और मैनिफ़ेस्ट की जानकारी नया शिक्षक-अनुरोध किए बिना पढ़ी जा सकती है।
  • अंतिम टेस्ट डेटा का मूल्यांकन, सुधार के दौरान होने वाले वैलिडेशन से अलग है।
  • आउटपुट मैनिफ़ेस्ट में असली फ़ाइलें, सुरक्षित सापेक्ष पथ, बाइट आकार और सही SHA-256 मान होने चाहिए।
उदाहरण · text
TrainingProject return contract (dictionary shapes)
from_file: validates configuration, attaches its owned run; no weight updates.
plan: {schema_version, resolved_configuration, compatibility, data_sharing,
       budgets, topics, artifacts, fingerprints}; dry_run must be true.
run/resume: {run_id, status, stop_reason, report_path, unmet_criteria}.
status/pause/cancel: {run_id, status, stop_reason, report_path, unmet_criteria}.
stop_reason is null until terminal; run/resume block until terminal or paused.
pause blocks until owned workers acknowledge an atomic checkpoint.
cancel blocks until owned workers stop; a failed stop raises CancellationError.
evaluate: {run_id, split, accepted, criteria, regressions, report_path}.
export: {run_id, format, artifact_path, manifest_path, sha256}.
Returned paths are local, resolved paths; no model upload is implied.
Status output is redacted and may be read without opening an API connection.
from_file requires path: str | os.PathLike and a nonempty api_key: str.
plan accepts dry_run=True only; False is ConfigurationError, not execution.
evaluate accepts split="validation" or "test"; defaults to test.
export accepts safetensors or adapters when supported by the selected adapter.
All method keyword options are keyword-only. Unlisted arguments are rejected.

विफलताओं को छिपाए बिना संभालें

प्रोजेक्ट की त्रुटि-कक्षाएँ TrainingError से निकलती हैं और CLI के एग्ज़िट कोड से जुड़ी हैं। कॉन्फ़िगरेशन या अनुकूलता की जाँच ट्रेनिंग शुरू होने से पहले विफल हो सकती है। बजट या मूल्यांकन की विफलता पर रिपोर्ट और अधूरे मानदंड सुरक्षित रहते हैं। वर्कर रोकने या चेकपॉइंट की त्रुटि तब तक विफलता मानी जाएगी, जब तक सुरक्षित सफ़ाई की पुष्टि न हो।

  • सफल विधियाँ दस्तावेज़ में बताए गए शब्दकोश लौटाती हैं। कसौटी पूरी न होने पर मूल्यांकन रिपोर्ट सहेजकर EvaluationFailedError दिया जाता है।
  • API key, प्राधिकरण हेडर, पूरा परिवेश या निजी ट्रेनिंग उदाहरण कभी लॉग न करें।
  • अपवाद आते ही अपने-आप दोबारा कोशिश न करें। पहले रन और सेवा की स्थिति देखें।
Python त्रुटियाँ और CLI एग्ज़िट कोड
फ़ील्ड या इंटरफ़ेसप्रकार या परिणामडिफ़ॉल्ट या एग्ज़िट कोडव्यवहार और सत्यापन
ConfigurationError TrainingError 2 स्कीमा, तर्क, पथ या स्थिति अमान्य है, या दिया बदलाव समर्थित नहीं। दोबारा कोशिश से पहले इनपुट ठीक करें।
CompatibilityError TrainingError 3 एडैप्टर, मॉडल, हार्डवेयर, संख्यात्मक परिशुद्धता, वितरण या फ़ॉर्मैट समर्थित नहीं है।
AuthenticationError TrainingError 4 कुंजी मौजूद नहीं या उसकी अवधि बीत गई, खाते का अधिकार अस्वीकृत है या शिक्षक के साथ साझा करना मना है; संदेश में गोपनीय जानकारी न दें।
BudgetExceededError TrainingError 5 स्वीकृति से पहले तय बजट पूरा हो गया। मान्य चेकपॉइंट और अधूरे मानदंड सुरक्षित रखें।
EvaluationFailedError TrainingError 6 ज़रूरी मानदंड पूरे नहीं हुए, सुधार रुक गया या प्रतिगमन बना रहा। मूल्यांकन रिपोर्ट सुरक्षित रखें।
CheckpointError TrainingError 7 पुनर्प्राप्ति-स्थिति अमान्य, अधूरी या बेमेल है। ज़बरदस्ती फिर शुरू न करें।
CancellationError TrainingError 7 अपने कार्यकर्ता सुरक्षित रूप से रुके, इसकी पुष्टि नहीं हुई; सफ़ाई जारी रखें।
ExportError TrainingError 7 सामग्री असमर्थित या अमान्य है, पथ असुरक्षित है या चेकसम जाँच विफल हुई; इसे न सौंपें।
TrainingError Exception 7 मूल ट्रेनिंग विफल हुई। सूची की सभी लक्ष्य-त्रुटियाँ इसी से निकली हैं; संवेदनशील विवरण हटाई जाँच-सूचनाएँ सुरक्षित रखें।
उदाहरण · python
import os
from fusionpointai_training import TrainingProject
from fusionpointai_training.errors import (
    AuthenticationError, BudgetExceededError, CompatibilityError,
    ConfigurationError, EvaluationFailedError, TrainingError,
)

try:
    project = TrainingProject.from_file(
        "./german-project/training.json",
        api_key=os.environ.get("FUSIONPOINTAI_API_KEY", ""),
    )
    project.plan(dry_run=True)
    project.run()
    result = project.evaluate(split="test")
except (ConfigurationError, CompatibilityError):
    print("Correct the configuration before starting a new run.")
except AuthenticationError:
    print("Check access without logging the key.")
except BudgetExceededError:
    print("Preserve the checkpoint. A larger approved budget requires a new plan.")
except EvaluationFailedError:
    print("Preserve failed criteria; do not publish this model as accepted.")
except TrainingError:
    print("Inspect redacted diagnostics; do not blindly repeat a write.")
# CancellationError, CheckpointError and ExportError also inherit TrainingError.
उदाहरण · python
from fusionpointai_training import register_evaluator

def category_match(prediction, target, row):
    return float(prediction.strip().casefold() == target.strip().casefold())

register_evaluator("category_match", category_match, version="1")
# Register before project.plan() in the same Python process.
# In rubric.json: "metric": "category_match", "minimum_score": 0.85
# This scorer measures category equality, not open-ended semantic correctness.