-
Notifications
You must be signed in to change notification settings - Fork 33.8k
[i18n-ar] Translated file : docs/source/ar/pipeline_webserver.md into Arabic
#33066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
AhmedAlmaghz
wants to merge
29
commits into
huggingface:main
from
AhmedAlmaghz:Add_docs_source_ar_pipeline_webserver.md
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
9a2fda7
Add docs/source/ar/pipeline_webserver.md to Add_docs_source_ar_pipeli…
AhmedAlmaghz 1ca6764
Create _toctree.yml
AhmedAlmaghz 1a94839
Update _toctree.yml
AhmedAlmaghz 41d72ef
Update _toctree.yml - tasks_explained
AhmedAlmaghz 7765d6c
Update _toctree.yml - tokenizer_summary
AhmedAlmaghz 5ccdf41
Update _toctree.yml - model_summary
AhmedAlmaghz e99f0ef
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz e5977e0
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 0931ebd
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 7207537
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz bcf5bab
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 3e9b311
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 775a5e4
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz e274fc7
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz b4393c7
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz fdce305
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 009d23e
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 1c14370
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 7d5d940
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 30def2e
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 5208c4d
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz d7f812c
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 49d1e63
Update docs/source/ar/pipeline_webserver.md
AhmedAlmaghz 75a5f60
Update _toctree.yml - attention
AhmedAlmaghz 9a99d59
Update _toctree.yml - pad_truncation
AhmedAlmaghz e0f2d6c
Update _toctree.yml - bertology
AhmedAlmaghz acc1351
Update _toctree.yml - perplexity
AhmedAlmaghz 7bf45cf
Update _toctree.yml - pipeline_webserver
AhmedAlmaghz 7ceddcb
Merge pull request #29 from AhmedAlmaghz/Update_toctree_yml
AhmedAlmaghz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # استخدام خطوط الأنابيب لخادم ويب | ||
|
|
||
| <Tip> | ||
|
|
||
| إن إنشاء محرك استدلال موضوع معقد، وقد يعتمد "أفضل" حل على مساحة المشكلة لديك. هل أنت على وحدة المعالجة المركزية أو وحدة معالجة الرسومات؟ هل تريد أدنى مستوى من التأخير، أو أعلى مستوى من الإنتاجية، أو دعم العديد من النماذج، أو فقط تحسين نموذج واحد محدد؟ هناك العديد من الطرق لتناول هذا الموضوع، لذا فإن ما سنقدمه هو إعداد افتراضي جيد للبدء، ولكنه قد لا يكون الحل الأمثل بالنسبة لك. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| </Tip> | ||
|
|
||
| الشيء الرئيسي الذي يجب فهمه هو أننا يمكن أن نستخدم مؤشرًا، تمامًا كما تفعل [على مجموعة بيانات](pipeline_tutorial#using-pipelines-on-a-dataset)، نظرًا لأن خادم الويب هو أساسًا نظام ينتظر الطلبات ويعالجها عند استلامها. | ||
|
|
||
| عادةً ما تكون خوادم الويب متعددة الإرسال (متعددة الخيوط، غير متزامنة، إلخ) للتعامل مع الطلبات المختلفة بشكل متزامن. من ناحية أخرى، فإن خطوط الأنابيب (وبشكل رئيسي النماذج الأساسية) ليست رائعة حقًا للتوازي؛ حيث تستهلك الكثير من ذاكرة الوصول العشوائي، لذا من الأفضل منحها جميع الموارد المتاحة عندما تعمل أو أنها مهمة مكثفة الحساب. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| سنحل ذلك من خلال جعل خادم الويب يتعامل مع الحمل الخفيف لاستقبال الطلبات وإرسالها، ووجود خيط واحد للتعامل مع العمل الفعلي. سيستخدم هذا المثال `starlette`. إطار العمل الفعلي ليس مهمًا حقًا، ولكن قد يتعين عليك ضبط الكود أو تغييره إذا كنت تستخدم إطار عمل آخر لتحقيق نفس التأثير. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| أنشئ `server.py`: | ||
|
|
||
| ```py | ||
| from starlette.applications import Starlette | ||
| from starlette.responses import JSONResponse | ||
| from starlette.routing import Route | ||
| from transformers import pipeline | ||
| import asyncio | ||
|
|
||
|
|
||
| async def homepage(request): | ||
| payload = await request.body() | ||
| string = payload.decode("utf-8") | ||
| response_q = asyncio.Queue() | ||
| await request.app.model_queue.put((string, response_q)) | ||
| output = await response_q.get() | ||
| return JSONResponse(output) | ||
|
|
||
|
|
||
| async def server_loop(q): | ||
| pipe = pipeline(model="google-bert/bert-base-uncased") | ||
| while True: | ||
| (string, response_q) = await q.get() | ||
| out = pipe(string) | ||
| await response_q.put(out) | ||
|
|
||
|
|
||
| app = Starlette( | ||
| routes=[ | ||
| Route("/", homepage, methods=["POST"]), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| @app.on_event("startup") | ||
| async def startup_event(): | ||
| q = asyncio.Queue() | ||
| app.model_queue = q | ||
| asyncio.create_task(server_loop(q)) | ||
| ``` | ||
|
|
||
| الآن يمكنك تشغيله باستخدام: | ||
|
|
||
| ```bash | ||
| uvicorn server:app | ||
| ``` | ||
|
|
||
| ويمكنك الاستعلام عنه: | ||
|
|
||
| ```bash | ||
| curl -X POST -d "test [MASK]" http://localhost:8000/ | ||
| #[{"score":0.7742936015129089,"token":1012,"token_str":".","sequence":"test."},...] | ||
| ``` | ||
|
|
||
| وهكذا، لديك الآن فكرة جيدة عن كيفية إنشاء خادم ويب! | ||
|
|
||
| ما هو مهم حقًا هو أننا نحمل النموذج **مرة واحدة** فقط، لذلك لا توجد نسخ من النموذج على خادم الويب. بهذه الطريقة، لا يتم استخدام ذاكرة الوصول العشوائي غير الضرورية. تسمح آلية وضع الطابور بالقيام بأشياء متقدمة مثل ربما تجميع بعض العناصر قبل الاستدلال لاستخدام الدفعات الديناميكية: | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| <Tip warning={true}> | ||
|
|
||
| تم كتابة عينة الكود أدناه بشكل مقصود مثل كود وهمي للقراءة. لا تقم بتشغيله دون التحقق مما إذا كان منطقيًا لموارد النظام الخاص بك! | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| </Tip> | ||
|
|
||
| ```py | ||
| (string, rq) = await q.get() | ||
| strings = [] | ||
| queues = [] | ||
| while True: | ||
| try: | ||
| (string, rq) = await asyncio.wait_for(q.get(), timeout=0.001) # 1ms | ||
| except asyncio.exceptions.TimeoutError: | ||
| break | ||
| strings.append(string) | ||
| queues.append(rq) | ||
| strings | ||
| outs = pipe(strings, batch_size=len(strings)) | ||
| for rq, out in zip(queues, outs): | ||
| await rq.put(out) | ||
| ``` | ||
|
|
||
| مرة أخرى، تم تحسين الكود المقترح للقراءة، وليس ليكون أفضل كود. أولاً، لا يوجد حد لحجم الدفعة، والذي عادةً ما لا يكون فكرة عظيمة. بعد ذلك، يتم إعادة تعيين المهلة في كل عملية استرداد للصف، مما يعني أنه قد يتعين عليك الانتظار لفترة أطول بكثير من 1 مللي ثانية قبل تشغيل الاستدلال (تأخير الطلب الأول بهذا القدر). | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| سيكون من الأفضل وجود موعد نهائي واحد لمدة 1 مللي ثانية. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| سيظل هذا ينتظر دائمًا لمدة 1 مللي ثانية حتى إذا كان الطابور فارغًا، والذي قد لا يكون الأفضل نظرًا لأنك تريد على الأرجح البدء في إجراء الاستدلال إذا لم يكن هناك شيء في الطابور. ولكن ربما يكون منطقيًا إذا كانت الدفعات مهمة حقًا لحالتك الاستخدام. مرة أخرى، لا يوجد حل واحد الأفضل. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## بعض الأشياء التي قد ترغب في مراعاتها | ||
|
|
||
| ### التحقق من الأخطاء | ||
|
|
||
| هناك الكثير مما يمكن أن يسير على ما يرام في الإنتاج: نفاد الذاكرة، أو نفاد المساحة، أو قد يفشل تحميل النموذج، أو قد يكون الاستعلام خاطئًا، أو قد يكون الاستعلام صحيحًا ولكنه يفشل في التشغيل بسبب إعداد نموذج غير صحيح، وهكذا. | ||
|
|
||
| من الجيد بشكل عام إذا قام الخادم بإخراج الأخطاء إلى المستخدم، لذا فإن إضافة الكثير من عبارات `try..except` لعرض هذه الأخطاء فكرة جيدة. ولكن ضع في اعتبارك أنه قد يكون أيضًا خطرًا أمنيًا للكشف عن جميع هذه الأخطاء اعتمادًا على سياق الأمان الخاص بك. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### كسر الدائرة | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| عادةً ما تبدو خوادم الويب أفضل عندما تقوم بكسر الدائرة. وهذا يعني أنها تعيد أخطاء صحيحة عندما تكون مثقلة بالأعباء بدلاً من الانتظار إلى أجل غير مسمى للاستعلام. قم بإرجاع خطأ 503 بدلاً من الانتظار لفترة طويلة جدًا أو 504 بعد فترة طويلة. | ||
|
|
||
| من السهل نسبيًا تنفيذ ذلك في الكود المقترح نظرًا لوجود طابور واحد. إن النظر في حجم الطابور هو طريقة أساسية لبدء إعادة الأخطاء قبل فشل خادم الويب بسبب التحميل الزائد. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### حظر الخيط الرئيسي | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| حاليًا، PyTorch غير مدرك للأساليب غير المتزامنة، وسيؤدي الحساب إلى حظر الخيط الرئيسي أثناء تشغيله. وهذا يعني أنه سيكون من الأفضل إذا تم إجبار PyTorch على التشغيل على خيط/عملية خاصة به. لم يتم ذلك هنا لأن الكود أكثر تعقيدًا (في الغالب لأن الخيوط والأساليب غير المتزامنة والطوابير لا تتوافق معًا). ولكن في النهاية، فإنه يؤدي نفس الوظيفة. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| سيكون هذا مهمًا إذا كان الاستدلال للعناصر الفردية طويلًا (> 1 ثانية) لأنه في هذه الحالة، يجب أن ينتظر كل استعلام أثناء الاستدلال لمدة 1 ثانية قبل حتى تلقي خطأ. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### الدفعات الديناميكية | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
|
|
||
| بشكل عام، قد لا يكون التجميع تحسينًا بالمقارنة مع تمرير عنصر واحد في كل مرة (راجع [تفاصيل الدفعات](./main_classes/pipelines#pipeline-batching) لمزيد من المعلومات). ولكنه يمكن أن يكون فعالًا جدًا عند استخدامه في الإعداد الصحيح. في واجهة برمجة التطبيقات، لا يوجد تجميع ديناميكي بشكل افتراضي (الكثير من الفرص لتباطؤ). ولكن بالنسبة لاستدلال BLOOM - وهو نموذج كبير جدًا - فإن التجميع الديناميكي **أساسي** لتوفير تجربة جيدة للجميع. | ||
|
AhmedAlmaghz marked this conversation as resolved.
Outdated
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.