Skip to main content

SigmaFlow is a Python package designed to optimize the performance of task-flow related to LLMs or MLLMs

Project description

banner

访问量统计 license issue resolution open issues

👋 join us on WeChat

SigmaFlow

SigmaFlow is a Python package designed to optimize the performance of task-flow related to LLMs or MLLMs. comfyUI demo

graph LR
    %% ========================
    %% Nodes definition section
    %% ========================
    计算BMI[/"计算BMI"/]
    是否确诊{"是否确诊"}
    推断最有可能疾病["推断最有可能疾病"]
    身高(["身高"])
    年龄(["年龄"])
    提取症状["提取症状"]
    患者信息(["患者信息"])
    疾病列表(["疾病列表"])
    获取出生日期["获取出生日期"]
    治疗建议(["治疗建议"])
    计算年龄[/"计算年龄"/]
    体重(["体重"])
    诊断["诊断"]
    治疗推荐["治疗推荐"]
    获取身高体重["获取身高体重"]
    出生日期(["出生日期"])
    exit[["exit"]]
    症状(["症状"])
    疾病(["疾病"])
    BMI(["BMI"])
    搜索疾病列表("搜索疾病列表")

    %% ========================
    %% Links definition section
    %% ========================
    症状 --> 每个症状
    出生日期 ==> 计算年龄 ==> 年龄
    治疗建议 ==o|total: 6.26s| exit
    患者信息 ==> 提取症状 ==>|1.02s| 症状
    患者信息 ==> 获取出生日期 ==>|1.05s| 出生日期
    症状 ==> 搜索疾病列表 ==>|1.02s| 疾病列表
    患者信息 ==> 诊断 ==>|1.01s| 疾病
    身高 & 体重 ==> 计算BMI ==> BMI
    患者信息 ==> 获取身高体重 ==>|1.06s| 身高 & 体重
    疾病 ==>|1.02s| 是否确诊
    患者信息 & 疾病列表 ==> 推断最有可能疾病 ==>|1.02s| 疾病
    是否确诊 ==>|无法确定| 提取症状 & 获取出生日期 & 获取身高体重
    患者信息 & 疾病 & 年龄 & BMI ==> 治疗推荐 ==>|1.02s| 治疗建议

    %% ================
    %% Subgraph section
    %% ================
    subgraph 每个症状
        搜索疾病列表
    end

    %% ========================
    %% Style definition section
    %% ========================
    classDef LLMNODE fill:#ECE4E2,color:black
    class 获取出生日期,诊断,治疗推荐,提取症状,获取身高体重,推断最有可能疾病 LLMNODE
    classDef DATA fill:#9BCFB8,color:black
    class 疾病,症状,出生日期,BMI,体重,年龄,治疗建议,患者信息,身高,疾病列表 DATA
    classDef BRANCHNODE fill:#445760,color:white
    class 是否确诊 BRANCHNODE
    classDef CODENODE fill:#FFFFAD,color:black
    class 计算BMI,计算年龄 CODENODE
    classDef LOOPNODE fill:none,stroke:#CC8A4D,stroke-dasharray:5 5,stroke-width:2px
    class 每个症状 LOOPNODE
    classDef RAGNODE fill:#FE929F,color:black
    class 搜索疾病列表 RAGNODE
    classDef EXITNODE fill:#3D3E3F,color:white
    class exit EXITNODE
    classDef INPUTDATA fill:#D64747,color:black
    class 患者信息 INPUTDATA
    linkStyle 0 fill:none,stroke:#CC8A4D,stroke-dasharray:5 5,stroke-width:2px
gantt
title Task Timeline
dateFormat  x
axisFormat  %M:%S.%L
section pid_00
诊断: 0, 1023ms
获取身高体重: 2046, 1035ms
每个症状: 3083, 12ms
搜索疾病列表: 3095, 1024ms
搜索疾病列表: 4119, 1023ms
section pid_01
获取出生日期: 2045, 1029ms
计算BMI: 3076, 11ms
治疗推荐: 3088, 1027ms
搜索疾病列表: 4115, 1025ms
推断最有可能疾病: 5141, 1025ms
section pid_02
提取症状: 2045, 1043ms
搜索疾病列表: 3089, 1022ms
搜索疾病列表: 4112, 1021ms
section pid_03
是否确诊: 1020, 1035ms
计算年龄: 3071, 25ms
搜索疾病列表: 3096, 1022ms
搜索疾病列表: 4118, 1023ms

Introduction

SigmaFlow is a Python package designed to optimize the performance of task-flow related to Large Language Models (LLMs) or Multimodal Large Language Models (MLLMs). It ensures efficient parallel execution of task-flow while maintaining dependency constraints, significantly enhancing the overall performance.

SigmaFlow 是一个 Python 包,旨在优化与大模型 (LLMs or MLLMs) 相关任务流的性能。在满足依赖关系的前提下,确保任务流的高效并行执行,从而显著提高整体性能。

Features

  • Dependency Management: Handles task dependencies efficiently, ensuring correct execution order.

    依赖管理:高效处理任务依赖关系,确保正确的执行顺序。

  • Parallel Execution: Maximizes parallelism to improve performance.

    并行执行:最大化并行性以提高性能。

  • Loop Handling: Supports tasks with loop structures.

    循环处理:支持带有循环结构的任务。

  • Easy Integration: Simple and intuitive API for easy integration with existing projects.

    易于集成:简单直观的 API,便于与现有项目集成。

Installation

You can install SigmaFlow via pip:

你可以通过 pip 安装 SigmaFlow:

pip install SigmaFlow

Usage

Here is a basic example to get you started:

下面是一个基本示例,帮助你快速入门:

Example Code
from SigmaFlow import SigmaFlow, Prompt

# set custom prompt
example_prompt = Prompt("""
...
{inp1}
xxx
""", keys=['{inp1}'])

# set api
def llm_api(inp):
    ...
    return out

def rag_api(inp):
    ...
    return out

# set input data
data = {
    'inp': 'test input text ...',
}

# set pipeline
demo_pipe = {
    'process_input': {
        'prompt': example_prompt,
        'format': {'out1': list, 'out2': str}, # check return json format
        'inp': ['inp'],
        'out': ['out1', 'out2'],
        'next': ['rag1', 'loop_A'], # specify the next pipeline
    },
    'rag1': {
        'rag_backend': rag_api2, # specific api can be set for the current pipe via 'rag_backend' or 'llm_backend'.
        'inp': ['out2'],
        'out': 'out8',
    },
    'loop_A': { # here is iterating over a list 'out1'
        'inp': 'out1',
        'pipe_in_loop': ['rag2', 'llm_process', 'rag3', 'rag4', 'llm_process2', 'llm_process3'],
        'next': ['exit'], # 'exit' is specific pipe mean to end
    },
    'rag2': {
        'inp': ['out1'],
        'out': 'out3',
    },
    'llm_process2': {
        'prompt': llm_process2_prompt,
        'format': {'xxx': str, "xxx": str},
        'inp': ['inp', 'out4', 'out8'],
        'out': 'final_out1',
    },
    ...
}

# running pipeline
pipeline = SigmaFlow(demo_pipe, llm_api, rag_api)
result, info = pipeline.run(data, core_num=4, save_pref=True)

Logs are stored in the logs folder. If save_pref is true, you can see the relevant performance report.

日志存储在logs文件夹下,如果save_preftrue,你可以看到相关的性能报告。

For a complete example, please refer to the example directory.

完整示例请参考example目录。

Documentation

For detailed documentation, please visit our official documentation page.

有关详细文档,请访问我们的官方文档页面。

Contributing

We welcome contributions from the community. Please read our contributing guide to get started.

我们欢迎来自社区的贡献。请阅读我们的贡献指南开始。

License

SigmaFlow is licensed under the Apache License Version 2.0. See the LICENSE file for more details.

SigmaFlow 采用 Apache License Version 2.0 许可证。有关详细信息,请参阅许可证文件。

Acknowledgements

Special thanks to all contributors and the open-source community for their support.

特别感谢所有贡献者和开源社区的支持。

Contact

For any questions or issues, please open an issue on our GitHub repository.

如有任何问题或意见,请在我们的GitHub 仓库提交 issue。

Star History Chart

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sigmaflow-0.0.2.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sigmaflow-0.0.2-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

Details for the file sigmaflow-0.0.2.tar.gz.

File metadata

  • Download URL: sigmaflow-0.0.2.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sigmaflow-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6a38fc1d2e437a7f7ec560f72b24b601415d91407e6b4d0cd9580d8369b4ee8e
MD5 8a4e568d7e4bc683fb849da463f92831
BLAKE2b-256 8ea2eaf380d36aac6bc629b6492dd32eac98d9ac3e15a64798e828ca202e4701

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigmaflow-0.0.2.tar.gz:

Publisher: release.yml on maokangkun/SigmaFlow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sigmaflow-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: sigmaflow-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 41.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sigmaflow-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 100a754c227a11ba6ab53c4dbb6d493c467a084e94adb5b18813eec404f6eafa
MD5 462b0996300b7699cd352edb063f3f6a
BLAKE2b-256 cae85c88cd1e9556f7d835cc68939100feab43ce6de98581d82119b939ea8a89

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigmaflow-0.0.2-py3-none-any.whl:

Publisher: release.yml on maokangkun/SigmaFlow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page