# نقاط نهاية الاستدلال

توفّر نقاط الاستدلال (Inference Endpoints) حلاً إنتاجياً آمناً لنشر أي نماذج `transformers` و`sentence-transformers` و`diffusers` بسهولة على بنية تحتية مخصصة وقابلة للتوسع التلقائي تديرها Hugging Face. يُبنى كل نقطة استدلال من نموذج موجود على [Hub](https://huggingface.co/models). في هذا الدليل، سنتعلم كيفية إدارة نقاط الاستدلال برمجياً باستخدام `huggingface_hub`. لمزيد من المعلومات حول منتج نقاط الاستدلال نفسه، راجع [وثائقه الرسمية](https://huggingface.co/docs/inference-endpoints/index).

يفترض هذا الدليل أن `huggingface_hub` مثبّت بشكل صحيح وأن جهازك مسجّل الدخول. راجع [دليل البدء السريع](https://huggingface.co/docs/huggingface_hub/quick-start#quickstart) إذا لم يكن الأمر كذلك بعد. الإصدار الأدنى الذي يدعم واجهة برمجة تطبيقات نقاط الاستدلال هو `v0.19.0`.

> [!TIP]
> **جديد:** أصبح من الممكن الآن نشر نقطة استنتاج من [كتالوج نماذج HF](https://endpoints.huggingface.co/catalog) عبر استدعاء API بسيط. الكتالوج هو قائمة مُنتقاة بعناية من النماذج التي يمكن نشرها بإعدادات مُحسّنة. لا تحتاج إلى تكوين أي شيء، فنحن نتولى جميع الأعمال الثقيلة نيابةً عنك! جميع النماذج والإعدادات مضمونة أنها خضعت للاختبار لتوفير أفضل توازن بين التكلفة والأداء. يعمل [create_inference_endpoint_from_catalog()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.create_inference_endpoint_from_catalog) بنفس طريقة [create_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.create_inference_endpoint)، مع عدد أقل بكثير من المعاملات التي يجب تمريرها. يمكنك استخدام [list_inference_catalog()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.list_inference_catalog) لاسترجاع الكتالوج برمجياً.
>
> يرجى ملاحظة أن هذه الميزة لا تزال تجريبية. أخبرنا برأيك إذا قمت باستخدامها!

يتم نشر كل نموذج في الكتالوج عبر *وصفة*: وهي مجموعة من العتاد ومحرك الاستدلال التي تم اختبارها لهذا النموذج. يعيد [list_inference_catalog()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.list_inference_catalog) النماذج مع وصفاتها، ويقبل عوامل تصفية على جانب الخادم (`accelerator`، `engine`، `license`، `task`، `search`، `limit`):

```py
>>> from huggingface_hub import list_inference_catalog
>>> catalog = list_inference_catalog(task="text-generation", accelerator="neuron")
>>> catalog[0]
InferenceCatalogModel(repo_id='meta-llama/Llama-3.1-8B-Instruct', name='Llama-3.1-8B-Instruct', ...)
>>> catalog[0].recipes
[InferenceCatalogRecipe(id='sizzling-biryani-g4xsi1ac', accelerator='gpu', engine='vllm', gguf_file=None, revision=None),
 InferenceCatalogRecipe(id='artisanal-quinoa-yz9ynamx', accelerator='neuron', engine='vllmNeuron', gguf_file=None, revision=None)]
```

مرّر `repo_id` إلى [create_inference_endpoint_from_catalog()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.create_inference_endpoint_from_catalog) لنشر الوصفة الافتراضية للنموذج، مع إمكانية تضييقها اختيارياً باستخدام `accelerator` (`"cpu"` أو `"gpu"` أو `"neuron"`) و`gguf_file`، أو مرّر `recipe_id` لنشر وصفة محددة بدقة:

```py
>>> from huggingface_hub import create_inference_endpoint_from_catalog
>>> endpoint = create_inference_endpoint_from_catalog(repo_id="openai/gpt-oss-120b")
>>> endpoint = create_inference_endpoint_from_catalog(recipe_id="artisanal-quinoa-yz9ynamx")
```

## ابحث عن أجهزة لتوزيع عليها

تعتمد القيم المقبولة لـ `accelerator` و`vendor` و`region` و`instance_type` و`instance_size` في [create_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.create_inference_endpoint) على بعضها البعض. استخدم [list_inference_endpoints_hardware()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.list_inference_endpoints_hardware) لعرض التوليفات الصالحة، إلى جانب سعرها لكل ساعة وحصة المعالج التسريعي (accelerator) الخاصة بمساحتك الاسم

```py
>>> from huggingface_hub import list_inference_endpoints_hardware

>>> for hw in list_inference_endpoints_hardware():
...     if hw.accelerator == "gpu" and hw.status == "available":
...         print(hw.vendor, hw.region, hw.instance_type, hw.instance_size, hw.price_per_hour)
aws us-east-1 nvidia-l4 x1 0.8
aws us-east-1 nvidia-l4 x4 3.8
...
```

الحصة لكل مساحة أسماء، لذا مرّر `namespace` الذي ستُنفّذ فيه (الافتراضي هو حسابك الخاص):

```py
>>> list_inference_endpoints_hardware(namespace="my-org")
```

أو عبر سطر الأوامر:

```bash
hf endpoints hardware --accelerator gpu
```

## إنشاء نقطة استنتاج

الخطوة الأولى هي إنشاء نقطة استنتاج باستخدام [create_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.create_inference_endpoint):

```py
>>> from huggingface_hub import create_inference_endpoint

>>> endpoint = create_inference_endpoint(
...     "my-endpoint-name",
...     repository="gpt2",
...     framework="pytorch",
...     task="text-generation",
...     accelerator="cpu",
...     vendor="aws",
...     region="us-east-1",
...     type="authenticated",
...     instance_size="x2",
...     instance_type="intel-icl"
... )
```

أو عبر سطر الأوامر:

```bash
hf endpoints deploy my-endpoint-name --repo gpt2 --framework pytorch --accelerator cpu --vendor aws --region us-east-1 --instance-size x2 --instance-type intel-icl --task text-generation

# Deploy from the catalog with a single command
hf endpoints catalog deploy --repo openai/gpt-oss-120b

# Deploy from the catalog with a specific accelerator
hf endpoints catalog deploy --repo openai/gpt-oss-120b --accelerator gpu

# Deploy an exact catalog recipe, as listed by 'hf endpoints catalog ls'
hf endpoints catalog deploy --recipe artisanal-quinoa-yz9ynamx
```

في هذا المثال، أنشأنا نقطة استنتاج `authenticated` باسم `"my-endpoint-name"`، لتقديم [gpt2](https://huggingface.co/gpt2) لـ `text-generation`. تعني نقطة الاستنتاج `authenticated` أنه يلزمك رمز وصول للوصول إلى واجهة برمجة التطبيقات. كما نحتاج إلى تقديم معلومات إضافية لتكوين متطلبات العتاد، مثل المزوّد، والمنطقة، والمسرِّع، ونوع المثيل، والحجم. يمكنك الاطلاع على قائمة الموارد المتاحة [هنا](https://api.endpoints.huggingface.cloud/#/v2%3A%3Aprovider/list_vendors). أو يمكنك إنشاء نقطة استنتاج يدويًا باستخدام [Web interface](https://ui.endpoints.huggingface.co) لراحة أكبر. راجع هذا [guide](https://huggingface.co/docs/inference-endpoints/guides/advanced) للتفاصيل حول الإعدادات المتقدمة واستخدامها.

القيمة التي يعيدها [create_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.create_inference_endpoint) هي كائن [InferenceEndpoint](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint):

```py
>>> endpoint
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2', status='pending', url=None)
```

أو عبر سطر الأوامر:

```bash
hf endpoints describe my-endpoint-name
```

إنه dataclass يحتوي على معلومات حول نقطة النهاية. يمكنك الوصول إلى سمات مهمة مثل `name`، `repository`، `status`، `task`، `created_at`، `updated_at`، وغيرها. وإذا كنت بحاجة إلى ذلك، يمكنك أيضًا الوصول إلى الاستجابة الخام من الخادم عبر `endpoint.raw`.

بمجرد إنشاء نقطة الاستدلال الخاصة بك، يمكنك العثور عليها على [لوحتك الشخصية](https://ui.endpoints.huggingface.co/).

![](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/huggingface_hub/inference_endpoints_created.png)

#### استخدام صورة مخصصة

يُبنى نقطة الاستدلال (Inference Endpoint) افتراضياً من صورة docker يوفرها Hugging Face. ومع ذلك، يمكن تحديد أي صورة docker باستخدام معامل `custom_image`. ومن الاستخدامات الشائعة تشغيل نماذج اللغة الكبيرة (LLMs) باستخدام إطار عمل [text-generation-inference](https://github.com/huggingface/text-generation-inference). ويمكن القيام بذلك على النحو التالي:

```python
# Start an Inference Endpoint running Zephyr-7b-beta on TGI
>>> from huggingface_hub import create_inference_endpoint
>>> endpoint = create_inference_endpoint(
...     "aws-zephyr-7b-beta-0486",
...     repository="HuggingFaceH4/zephyr-7b-beta",
...     framework="pytorch",
...     task="text-generation",
...     accelerator="gpu",
...     vendor="aws",
...     region="us-east-1",
...     type="authenticated",
...     instance_size="x1",
...     instance_type="nvidia-a10g",
...     custom_image={
...         "healthRoute": "/health",
...         "env": {
...             "MAX_BATCH_PREFILL_TOKENS": "2048",
...             "MAX_INPUT_LENGTH": "1024",
...             "MAX_TOTAL_TOKENS": "1512",
...             "MODEL_ID": "/repository"
...         },
...         "url": "ghcr.io/huggingface/text-generation-inference:1.1.0",
...     },
... )
```

القيمة التي يجب تمريرها كـ `custom_image` هي قاموس يحتوي على رابط (url) إلى حاوية docker وإعدادات لتشغيلها. لمزيد من التفاصيل حول ذلك، راجع [توثيق Swagger](https://api.endpoints.huggingface.cloud/#/v2%3A%3Aendpoint/create_endpoint).

بالنسبة إلى صورة مستضافة في سجل حاويات خاص، مرّر `container_registry_username` و، عند طلبه من السجل، `container_registry_password`. تُدعم بيانات الاعتماد فقط لحاوية مخصصة عادية:

```python
>>> endpoint = create_inference_endpoint(
...     # Other endpoint and hardware arguments omitted for brevity.
...     custom_image={"url": "private.registry.example/my-image:latest", "port": 8080},
...     container_registry_username="user",
...     container_registry_password="password",
... )
```

الخيارات المكافئة في سطر الأوامر هي `--container-registry-username` و`--container-registry-password`:

```bash
hf endpoints deploy my-endpoint ... --custom-image private.registry.example/my-image:latest \
  --container-registry-username user --container-registry-password password
```

يقبل `custom_image` أيضًا أنواع الحاويات الخاصة بكل محرك التي تدعمها الواجهة البرمجية، وذلك عن طريق استخدام اسم المحرك (`vLLM`، `vLLMNeuron`، `sGLang`، `tgi`، `tgiNeuron`، `tei`، `llamacpp`، `hfServe`، ...) كمفتاح في القاموس بدلاً من تركه مسطّحًا. يتلقى كل محرك حقول الحاوية المعتادة (`url`، `port`، `healthRoute`) بالإضافة إلى خيارات الضبط الخاصة به. يُمرَّر أي قاموس لا يحتوي على `url` في المستوى العلوي إلى الواجهة البرمجية دون أي تعديل، مما يعني أن المحركات التي تُضاف إلى الواجهة البرمجية لاحقًا ستعمل دون الحاجة إلى ترقية `huggingface_hub`:

```python
# Start an Inference Endpoint running the vLLM engine image
>>> endpoint = create_inference_endpoint(
...     "llama-3-1-8b-instruct-vllm",
...     repository="meta-llama/Llama-3.1-8B-Instruct",
...     framework="pytorch",
...     task="text-generation",
...     accelerator="gpu",
...     vendor="aws",
...     region="us-east-1",
...     instance_size="x1",
...     instance_type="nvidia-l4",
...     custom_image={
...         "vLLM": {
...             "url": "vllm/vllm-openai:v0.23.0",
...             "healthRoute": "/health",
...             "port": 8000,
...             "tensorParallelSize": 1,
...         }
...     },
... )
```

بدون مفتاح المحرك، يُرسل نفس القاموس كحاوية مخصصة عادية، لذا تُهمل الخيارات الخاصة بالمحرك (وهي هنا `tensorParallelSize`).

بالنسبة للحاويات التي تتطلب نقطة دخول مخصصة أو أعلام وقت تشغيل، مرّر `container_command` و/أو `container_args` (كلٌّ منهما قائمة من الرموز). تُخاط هذه إلى `model.command` و`model.args` في حمولة واجهة برمجة التطبيقات. وهي غير مرتبطة بالصور المخصصة: فصور المحركات المُدارة (مثل vLLM وSGLang) تقبل أعلام المحرك عبر `container_args` أيضاً. يتوفر الشيء نفسه من سطر الأوامر عبر `hf endpoints deploy ... --container-command "..." --container-args "..."`.

#### التوازي على أجهزة متعددة المعالجات

يعتمد vLLM و SGLang على معالج واحد افتراضيًا، بينما يُخصَّص للمنفذ كل معالجات مثيله، لذا فإن ترك التوازي غير مُعيَّن سيؤدي إلى تحميل النموذج على معالج واحد وإبقاء البقية خاملة مع الاستمرار في الإبلاغ عن الحالة الصحية، مما يعني أنك تدفع مقابل جميع المعالجات وتحصل على معدل إنتاجية معالج واحد. ولهذا السبب يرفض الواجهة البرمجية للتطبيقات (API) الآن مثل هذا النشر. (يشتق TGI عدد الأجزاء من المثلث ولا يتأثر.) عيّن `tensorParallelSize` لتقسيم نسخة واحدة من النموذج على المعالجات، أو `dataParallelSize` (vLLM فقط) لتشغيل نسخة واحدة لكل معالج:

```py
>>> endpoint = create_inference_endpoint(
...     "gpt-oss-120b-vllm",
...     repository="openai/gpt-oss-120b",
...     framework="custom",
...     accelerator="gpu",
...     instance_size="x8",
...     instance_type="nvidia-h200",
...     region="us-east-1",
...     vendor="aws",
...     custom_image={"vLLM": {"url": "vllm/vllm-openai:v0.23.0", "tensorParallelSize": 8}},
... )
```

من سطر الأوامر، يحدد `--engine` صورة محرك الإدارة وتُكتب العلمتان في ملفه الإعدادي:

```bash
hf endpoints deploy gpt-oss-120b-vllm --repo openai/gpt-oss-120b --framework custom \
  --accelerator gpu --instance-size x8 --instance-type nvidia-h200 --region us-east-1 --vendor aws \
  --engine vllm --custom-image vllm/vllm-openai:v0.23.0 --tensor-parallel-size 8
```

لإعادة ضبط نقطة نهاية مُنفَّذة، مرّر `tensor_parallel_size` بمفرده إلى [update()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.update) أو `hf endpoints update`. يُرسل `model.image` كوحدة كاملة ويتطلب `url`، لذا يتم جلب صورة نقطة النهاية الحالية وتحديثها في مكانها:

```py
>>> endpoint.update(tensor_parallel_size=4)
```

`container_args` (`--tp 8`) غير مكافئ: إذ يصل إلى المحرك كعلامة سطر أوامر، وليس كإعداد `model.image` الذي تتحقق منه الواجهة البرمجية مقابل عدد معجلات التسريع في المثيل. استخدمه لعلامات المحرك التي لا تحتوي على حقل صورة، ولحاويات مخصصة بسيطة لا تتضمن حقول توازٍ.

### الحصول على قائمة نقاط الاستدلال الموجودة

في بعض الحالات، قد تحتاج إلى إدارة نقاط الاستدلال (Inference Endpoints) التي أنشأتها سابقًا. إذا كنت تعرف الاسم، يمكنك استرجاعها باستخدام [get_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.get_inference_endpoint)، والتي تُرجع كائنًا من نوع [InferenceEndpoint](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint). أو يمكنك استخدام [list_inference_endpoints()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.list_inference_endpoints) للحصول على قائمة بجميع نقاط الاستدلال. تقبل كلا الطريقتين معاملًا اختياريًا باسم `namespace`. يمكنك تعيين `namespace` إلى أي منظمة أنت عضو فيها. وإلا، فإن القيمة الافتراضية هي اسم المستخدم الخاص بك.

```py
>>> from huggingface_hub import get_inference_endpoint, list_inference_endpoints

# Get one
>>> get_inference_endpoint("my-endpoint-name")
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2', status='pending', url=None)

# List all endpoints from an organization
>>> list_inference_endpoints(namespace="huggingface")
[InferenceEndpoint(name='aws-starchat-beta', namespace='huggingface', repository='HuggingFaceH4/starchat-beta', status='paused', url=None), ...]

# List all endpoints from all organizations the user belongs to
>>> list_inference_endpoints(namespace="*")
[InferenceEndpoint(name='aws-starchat-beta', namespace='huggingface', repository='HuggingFaceH4/starchat-beta', status='paused', url=None), ...]
```

أو عبر سطر الأوامر:

```bash
hf endpoints describe my-endpoint-name
hf endpoints ls --namespace huggingface
hf endpoints ls --namespace '*'
```

## تحقق من حالة النشر

في بقية هذا الدليل، سنفترض أن لدينا كائنًا من نوع [InferenceEndpoint](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint) يُسمى `endpoint`. ربما لاحظت أن نقطة النهاية تحتوي على خاصية `status` من النوع [InferenceEndpointStatus](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpointStatus). عند نشر نقطة الاستدلال وجعلها قابلة للوصول، يجب أن تكون الحالة `"running"` ويتم تعيين الخاصية `url`:

```py
>>> endpoint
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2', status='running', url='https://jpj7k2q4j805b727.us-east-1.aws.endpoints.huggingface.cloud')
```

قبل الوصول إلى حالة `"running"`، يمرّ Inference Endpoint عادةً بمرحلة `"initializing"` أو `"pending"`. يمكنك جلب الحالة الجديدة للنقطة النهائية بتشغيل [fetch()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.fetch). وكما هو الحال مع كل طريقة أخرى من [InferenceEndpoint](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint) تُرسل طلبًا إلى الخادم، فإن الخصائص الداخلية لـ`endpoint` تتغير في مكانها:

```py
>>> endpoint.fetch()
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2', status='pending', url=None)
```

أو عبر سطر الأوامر:

```bash
hf endpoints describe my-endpoint-name
```

بدلاً من جلب حالة نقطة الاستدلال (Inference Endpoint) أثناء الانتظار حتى تعمل، يمكنك استدعاء [wait()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.wait) مباشرةً. يتلقى هذا الدالة المساعدة كمدخلات معامل `timeout` ومعامل `fetch_every` (بالثواني)، وسيحجب الخيط (thread) حتى يتم نشر نقطة الاستدلال. القيم الافتراضية هي على التوالي `None` (بدون مهلة زمنية) و`5` ثوانٍ.

```py
# Pending endpoint
>>> endpoint
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2', status='pending', url=None)

# Wait 10s => raises a InferenceEndpointTimeoutError
>>> endpoint.wait(timeout=10)
    raise InferenceEndpointTimeoutError("Timeout while waiting for Inference Endpoint to be deployed.")
huggingface_hub._inference_endpoints.InferenceEndpointTimeoutError: Timeout while waiting for Inference Endpoint to be deployed.

# Wait more
>>> endpoint.wait()
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2', status='running', url='https://jpj7k2q4j805b727.us-east-1.aws.endpoints.huggingface.cloud')
```

إذا تم تعيين `timeout` واستغرق نقطة الاستدلال وقتًا طويلاً جدًا للتحميل، فسيتم رفع خطأ انتهاء المهلة `InferenceEndpointTimeoutError`.

## تشغيل الاستدلال

بمجرد أن يصبح نقطة الاستدلال الخاصة بك قيد التشغيل، يمكنك أخيراً تنفيذ الاستدلال عليها!

لـ [InferenceEndpoint](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint) خاصيتان هما `client` و`async_client` تُرجع على التوالي كائن [InferenceClient](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_client#huggingface_hub.InferenceClient) وكائن [AsyncInferenceClient](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_client#huggingface_hub.AsyncInferenceClient).

```py
# Run text_generation task:
>>> endpoint.client.text_generation("I am")
' not a fan of the idea of a "big-budget" movie. I think it\'s a'

# Or in an asyncio context:
>>> await endpoint.async_client.text_generation("I am")
```

إذا لم تكن نقطة الاستدلال قيد التشغيل، يتم رفع استثناء [InferenceEndpointError](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpointError):

```py
>>> endpoint.client
huggingface_hub._inference_endpoints.InferenceEndpointError: Cannot create a client for this Inference Endpoint as it is not yet deployed. Please wait for the Inference Endpoint to be deployed using `endpoint.wait()` and try again.
```

لمزيد من التفاصيل حول كيفية استخدام [InferenceClient](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_client#huggingface_hub.InferenceClient)، راجع [دليل الاستدلال](../guides/inference).

## إدارة دورة الحياة

الآن بعد أن رأينا كيفية إنشاء نقطة استنتاج (Inference Endpoint) وتنفيذ الاستنتاج عليها، دعونا نرى كيفية إدارة دورة حياتها.

> [!TIP]
> في هذا القسم، سنستعرض طرقًا مثل [pause()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.pause) و[resume()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.resume) و[scale_to_zero()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.scale_to_zero) و[update()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.update) و[delete()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.delete). جميع هذه الطرق هي أسماء بديلة أُضيفت إلى [InferenceEndpoint](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint) من أجل التسهيل. وإذا كنت تفضّل ذلك، يمكنك أيضًا استخدام الطرق العامة المعرّفة في `HfApi`: [pause_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.pause_inference_endpoint) و[resume_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.resume_inference_endpoint) و[scale_to_zero_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.scale_to_zero_inference_endpoint) و[update_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.update_inference_endpoint) و[delete_inference_endpoint()](/docs/huggingface_hub/v2.4.0/ar/package_reference/hf_api#huggingface_hub.HfApi.delete_inference_endpoint).

### إيقاف مؤقت أو التقليل إلى الصفر

لتقليل التكاليف عندما لا تكون نقطة الاستدلال قيد الاستخدام، يمكنك اختيار إما إيقافها مؤقتًا باستخدام [pause()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.pause) أو تصفيرها باستخدام [scale_to_zero()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.scale_to_zero).

> [!TIP]
> لا يتكبد أي تكلفة نقطة استنتاج *متوقفة مؤقتًا* أو *مُصغَّرة إلى الصفر*. والفرق بين الحالتين هو أن نقطة الاستنتاج *المتوقفة مؤقتًا* تحتاج إلى *استئناف* صريح باستخدام [resume()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.resume). في المقابل، ستبدأ نقطة الاستنتاج *المُصغَّرة إلى الصفر* تلقائيًا إذا تم إجراء استدعاء استنتاج إليها، مع تأخير إضافي لبدء التشغيل البارد. كما يمكن تكوين نقطة الاستنتاج لتُصغَّر إلى الصفر تلقائيًا بعد فترة معينة من عدم النشاط.

```py
# Pause and resume endpoint
>>> endpoint.pause()
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2', status='paused', url=None)
>>> endpoint.resume()
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2', status='pending', url=None)
>>> endpoint.wait().client.text_generation(...)
...

# Scale to zero
>>> endpoint.scale_to_zero()
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2', status='scaledToZero', url='https://jpj7k2q4j805b727.us-east-1.aws.endpoints.huggingface.cloud')
# Endpoint is not 'running' but still has a URL and will restart on first call.
```

أو عبر سطر الأوامر:

```bash
hf endpoints pause my-endpoint-name
hf endpoints resume my-endpoint-name
hf endpoints scale-to-zero my-endpoint-name
```

### تحديث متطلبات النموذج أو العتاد

في بعض الحالات، قد ترغب أيضًا في تحديث نقطة الاستدلال (Inference Endpoint) الخاصة بك دون إنشاء نقطة جديدة. يمكنك إما تحديث النموذج المضيف أو متطلبات الأجهزة لتشغيل النموذج. يمكنك القيام بذلك باستخدام [update()](/docs/huggingface_hub/v2.4.0/ar/package_reference/inference_endpoints#huggingface_hub.InferenceEndpoint.update):

```py
# Change target model
>>> endpoint.update(repository="gpt2-large")
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2-large', status='pending', url=None)

# Update number of replicas
>>> endpoint.update(min_replica=2, max_replica=6)
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2-large', status='pending', url=None)

# Update to larger instance
>>> endpoint.update(accelerator="cpu", instance_size="x4", instance_type="intel-icl")
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2-large', status='pending', url=None)

# Update the container arguments, e.g. engine flags on an endpoint running vLLM or SGLang.
# Replaces the current value, it is not appended.
>>> endpoint.update(container_args=["--enable-auto-tool-choice", "--tool-call-parser", "lfm2"])
InferenceEndpoint(name='my-endpoint-name', namespace='Wauplin', repository='gpt2-large', status='pending', url=None)
```

أو عبر سطر الأوامر:

```bash
hf endpoints update my-endpoint-name --repo gpt2-large
hf endpoints update my-endpoint-name --min-replica 2 --max-replica 6
hf endpoints update my-endpoint-name --accelerator cpu --instance-size x4 --instance-type intel-icl
hf endpoints update my-endpoint-name --container-args "--enable-auto-tool-choice --tool-call-parser lfm2"
# Merged into the image currently configured on the endpoint.
hf endpoints update my-endpoint-name --tensor-parallel-size 8
# Or replace the image entirely, in which case pass back the settings you want to keep.
hf endpoints update my-endpoint-name --engine vllm --custom-image vllm/vllm-openai:v0.23.0 --port 8000
```

### حذف نقطة النهاية

وأخيرًا، إذا لم تعد بحاجة إلى استخدام نقطة الاستدلال، يمكنك ببساطة استدعاء `~InferenceEndpoint.delete()`.

> [!WARNING]
> هذا إجراء غير قابل للتراجع سيقوم بإزالة نقطة النهاية بالكامل، بما في ذلك إعداداتها وسجلات استخدامها ومقاييس الاستخدام. لا يمكنك استعادة نقطة استدلال محذوفة.

## مثال شامل من البداية إلى النهاية

يتمثل استخدام نموذجي لنقاط الاستدلال (Inference Endpoints) في معالجة دفعة من المهام دفعة واحدة لتقليل تكاليف البنية التحتية. يمكنك أتمتة هذه العملية باستخدام ما رأيناه في هذا الدليل:

```py
>>> import asyncio
>>> from huggingface_hub import create_inference_endpoint

# Start endpoint + wait until initialized
>>> endpoint = create_inference_endpoint(name="batch-endpoint",...).wait()

# Run inference
>>> client = endpoint.client
>>> results = [client.text_generation(...) for job in jobs]

# Or with asyncio
>>> async_client = endpoint.async_client
>>> results = await asyncio.gather(*[async_client.text_generation(...) for job in jobs])

# Pause endpoint
>>> endpoint.pause()
```

أو إذا كان نقطة الاستدلال الخاصة بك موجودة بالفعل وموقوفة:

```py
>>> import asyncio
>>> from huggingface_hub import get_inference_endpoint

# Get endpoint + wait until initialized
>>> endpoint = get_inference_endpoint("batch-endpoint").resume().wait()

# Run inference
>>> async_client = endpoint.async_client
>>> results = await asyncio.gather(*[async_client.text_generation(...) for job in jobs])

# Pause endpoint
>>> endpoint.pause()
```

