dify blog 09月19日
Dify Workflow并行处理优化
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Dify Workflow通过引入并行处理能力,显著提升了复杂任务的执行效率。新版本支持同时执行多个分支,优化了传统串行处理模式中的延迟和响应时间。用户可通过简单操作创建并行分支,适用于翻译、模型比较等场景。嵌套并行处理允许多级并行结构,如科学写作助手案例展示了多级嵌套应用。迭代并行在循环中并行处理数据,如股票新闻情感分析,有效提升处理速度。条件并行则根据条件动态执行分支任务,如面试准备助手案例展示了基于对话数量和公司信息的条件分支。这些优化使Dify Workflow更灵活高效,适用于多模型协作和复杂工作流。

🔹Dify Workflow通过引入并行处理能力,显著提升了复杂任务的执行效率。新版本支持同时执行多个分支,优化了传统串行处理模式中的延迟和响应时间,适用于翻译、模型比较等场景。

🔸嵌套并行处理允许多级并行结构,如科学写作助手案例展示了多级嵌套应用,包括概念解释、隐喻类比分支、主题提取和内容生成等并行任务,提升处理效率和质量。

🔄迭代并行在循环中并行处理数据,如股票新闻情感分析案例,对每条新闻URL并行执行内容检索、观点提取和观点总结,有效提升处理速度,适用于大量数据结构相似的任务。

🌐条件并行则根据条件动态执行分支任务,如面试准备助手案例展示了基于对话数量和公司信息的条件分支,灵活运行不同并行任务,提高效率并保持条理性,适用于需要根据状态和需求同时执行复杂任务的场景。

🚀这些优化使Dify Workflow更灵活高效,支持多模型协作,简化复杂任务,动态调整执行路径,拓宽应用范围,更好地处理复杂工作情况。

Dify Workflow is widely used for its user-friendly setup and powerful functionality. However, previous versions executed steps serially, waiting for each node to complete before moving to the next. While providing a clear structure, this slowed processing for complex tasks, increasing latency and response times.

Dify v0.8.0 addresses these limitations by introducing parallel processing capabilities. Workflow can now execute multiple branches concurrently, enabling simultaneous processing of different tasks. This significantly improves execution efficiency, allowing LLM applications to handle complex workloads faster and with greater flexibility.

Creating parallel branches 

To define parallel branches in a Workflow:

  1. Hover over a node

  2. Click the + icon that appears

  3. Add different node types

The branches will execute in parallel and combine their outputs. Refer to the documentation for detailed instructions.

Workflow includes several parallel scenarios. Experiment with these to speed up processes. If you’ve built Workflows in earlier versions, consider restructuring them with parallel patterns to improve performance.

Simple parallelism 

For basic scenarios, create multiple parallel branches from a fixed node (e.g., the start node). This setup handles similar subtasks concurrently, such as translations or model comparisons. The video below shows simple parallelism in a model comparison workflow:

Nested parallelism

Nested parallelism allows for multi-level parallel structures within a Workflow. From an initial node, it branches into multiple parallel paths, each containing its own parallel processes. The "Science Writing Assistant" example shows two nesting levels:

  1. First level (Box 1): From the question classifier, two main branches emerge:

    a. Concept explanation (Box 1)

    b. Handling off-topic conversations ("Refuse small talk" branch)

    The concept explanation branch (Box 1) includes:

    - Metaphors and analogies branch for enhanced concept understanding

    - Theme extraction | Second level nesting (Box 2) for detailed concept analysis and content generation

  2. Second level (Box 2): The theme extraction branch performs two parallel tasks:

    a. Extract theme and search (Extract the theme -> Serper) for background information

    b. Extract theme and generate study plan (Study Plan -> Parameter Extractor -> TavilySearch)

This multi-level nested parallel structure is ideal for complex, multi-stage tasks like in-depth concept analysis and science communication content creation. It processes different concept aspects concurrently, including basic explanations, analogies, background research, and learning plans, improving processing efficiency and output quality.

Iterative Parallelism

Iteration parallelism involves parallel processing within a loop structure. The "Stock News Sentiment Analysis" example demonstrates this approach:

  1. Setup: Search and extract multiple news URLs for a specific stock.

  2. Iterative processing: For each URL, execute in parallel:

    a. Content retrieval: Use JinaReader to scrape and parse webpage content.

    b. Opinion extraction: Identify optimistic and pessimistic views using a parameter extractor.

    c. Opinion summarization: Use two independent LLM models to summarize optimistic and pessimistic views concurrently.

  3. Combine results: Consolidate all findings into a single table.

This method efficiently processes large volumes of news articles, analyzing sentiment from multiple perspectives to help investors make informed decisions. Parallel processing within iterations accelerates tasks with similar data structures, saving time and improving performance.

Conditional parallelism 

Conditional branch parallelism runs different parallel task branches based on conditions. The "Interview Preparation Assistant" example shows this setup:

  1. Main condition (IF/ELSE node): Splits process based on dialogue_count:

    a. First dialogue: Confirm interview role and company

    b. Later dialogues: Enter deeper processing

  2. Secondary condition (IF/ELSE 2 node): In later dialogues, branches based on existing company info and interview questions:

    a. Missing company info: Run parallel tasks to search company, scrape webpage, summarize company info

    b. Missing interview questions: Generate multiple questions in parallel

  3. Parallel task execution: For question generation, multiple LLM nodes start at the same time, each creating a different question

This IF/ELSE structure lets Workflow flexibly run different parallel tasks based on current state and needs. (The question classifier node can serve a similar function.) This improves efficiency while keeping things orderly. It suits situations needing simultaneous complex tasks based on various conditions, like this interview prep process.

Benefiting from Workflow parallelism 

These four parallel methods (simple, nested, iterative, and conditional) boost Dify Workflow's performance. They support multi-model teamwork, simplify difficult tasks, and adjust execution paths dynamically. These upgrades increase efficiency and broaden applications, handling tough work situations better. You can quickly try these new features in the matching templates on the explore page.

We will continue to enhance Workflow, offering more powerful and flexible automation solutions. Stay tuned!

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Dify Workflow 并行处理 效率优化 复杂任务 多模型协作
相关文章