From 342e4d7b417a474177d3798519910a927c473855 Mon Sep 17 00:00:00 2001 From: Kye Date: Tue, 27 Feb 2024 19:06:49 -0800 Subject: [PATCH] [CLEANUP] --- .gitignore | 2 +- Cargo.toml | 23 ++++---- playground/agents/multion_agent.py | 1 + .../{qdrant/usage_example.py => qdrant.py} | 1 - pyproject.toml | 5 +- .../rust_scripts}/concurrent_exec.rs | 0 .../rust_scripts}/cuda_wrapper.rs | 0 .../rust_scripts}/file_utils.rs | 0 .../rust_scripts}/multi_threading.rs | 0 src/main.rs | 59 +++++++++++++++++++ 10 files changed, 75 insertions(+), 16 deletions(-) rename playground/memory/{qdrant/usage_example.py => qdrant.py} (90%) rename {runtime => scripts/rust_scripts}/concurrent_exec.rs (100%) rename {runtime => scripts/rust_scripts}/cuda_wrapper.rs (100%) rename {runtime => scripts/rust_scripts}/file_utils.rs (100%) rename {runtime => scripts/rust_scripts}/multi_threading.rs (100%) create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore index bc35715f..d142b5e4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ Unit Testing Agent_state.json swarms/__pycache__ venv .DS_Store - +Cargo.lock .DS_STORE Cargo.lock swarms/agents/.DS_Store diff --git a/Cargo.toml b/Cargo.toml index 142a8652..87d3cd0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,15 @@ [package] -name = "engine" -version = "0.1.0" -edition = "2018" - -[lib] -name = "engine" -path = "runtime/concurrent_exec.rs" -crate-type = ["cdylib"] +name = "swarms-runtime" # The name of your project +version = "0.1.0" # The current version, adhering to semantic versioning +edition = "2021" # Specifies which edition of Rust you're using, e.g., 2018 or 2021 +authors = ["Your Name "] # Optional: specify the package authors +license = "MIT" # Optional: the license for your project +description = "A brief description of my project" # Optional: a short description of your project [dependencies] -pyo3 = { version = "0.15", features = ["extension-module"] } -rayon = "1.5.1" -log = "0.4.14" +cpython = "0.5" +rayon = "1.5" + +[dependencies.pyo3] +version = "0.20.3" +features = ["extension-module", "auto-initialize"] diff --git a/playground/agents/multion_agent.py b/playground/agents/multion_agent.py index 5534ddce..d1a02b8e 100644 --- a/playground/agents/multion_agent.py +++ b/playground/agents/multion_agent.py @@ -5,6 +5,7 @@ from swarms import Agent, ConcurrentWorkflow, Task # model model = MultiOnAgent(multion_api_key="api-key") + # out = model.run("search for a recipe") agent = Agent( agent_name="MultiOnAgent", diff --git a/playground/memory/qdrant/usage_example.py b/playground/memory/qdrant.py similarity index 90% rename from playground/memory/qdrant/usage_example.py rename to playground/memory/qdrant.py index b85f3089..8004ae02 100644 --- a/playground/memory/qdrant/usage_example.py +++ b/playground/memory/qdrant.py @@ -14,7 +14,6 @@ docs = loader.load() qdrant_client = qdrant.Qdrant( host="https://697ea26c-2881-4e17-8af4-817fcb5862e8.europe-west3-0.gcp.cloud.qdrant.io", collection_name="qdrant", - api_key="BhG2_yINqNU-aKovSEBadn69Zszhbo5uaqdJ6G_qDkdySjAljvuPqQ", ) qdrant_client.add_vectors(docs) diff --git a/pyproject.toml b/pyproject.toml index 00b4ae20..5bc05303 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,11 @@ [build-system] -requires = ["poetry-core>=1.0.0", "maturin"] +requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" - [tool.poetry] name = "swarms" -version = "4.1.9" +version = "4.2.0" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/runtime/concurrent_exec.rs b/scripts/rust_scripts/concurrent_exec.rs similarity index 100% rename from runtime/concurrent_exec.rs rename to scripts/rust_scripts/concurrent_exec.rs diff --git a/runtime/cuda_wrapper.rs b/scripts/rust_scripts/cuda_wrapper.rs similarity index 100% rename from runtime/cuda_wrapper.rs rename to scripts/rust_scripts/cuda_wrapper.rs diff --git a/runtime/file_utils.rs b/scripts/rust_scripts/file_utils.rs similarity index 100% rename from runtime/file_utils.rs rename to scripts/rust_scripts/file_utils.rs diff --git a/runtime/multi_threading.rs b/scripts/rust_scripts/multi_threading.rs similarity index 100% rename from runtime/multi_threading.rs rename to scripts/rust_scripts/multi_threading.rs diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 00000000..aff411b3 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,59 @@ +use pyo3::prelude::*; +use pyo3::types::PyList; +use rayon::prelude::*; +use std::fs; +use std::time::Instant; + +// Define the new execute function +fn execute(script_path: &str, threads: usize) -> PyResult<()> { + (0..threads).into_par_iter().for_each(|_| { + Python::with_gil(|py| { + let sys = py.import("sys").unwrap(); + let path: &PyList = match sys.getattr("path") { + Ok(path) => match path.downcast() { + Ok(path) => path, + Err(e) => { + eprintln!("Failed to downcast path: {:?}", e); + return; + } + }, + Err(e) => { + eprintln!("Failed to get path attribute: {:?}", e); + return; + } + }; + + if let Err(e) = path.append("lib/python3.11/site-packages") { + eprintln!("Failed to append path: {:?}", e); + } + + let script = fs::read_to_string(script_path).unwrap(); + py.run(&script, None, None).unwrap(); + }); + }); + Ok(()) +} + +fn main() -> PyResult<()> { + let args: Vec = std::env::args().collect(); + let threads = 20; + + if args.len() < 2 { + eprintln!("Usage: {} ", args[0]); + std::process::exit(1); + } + let script_path = &args[1]; + + let start = Instant::now(); + + // Call the execute function + execute(script_path, threads)?; + + let duration = start.elapsed(); + match fs::write("/tmp/elapsed.time", format!("booting time: {:?}", duration)) { + Ok(_) => println!("Successfully wrote elapsed time to /tmp/elapsed.time"), + Err(e) => eprintln!("Failed to write elapsed time: {:?}", e), + } + + Ok(()) +}