{"id":19329749,"url":"https://github.com/outerbounds/diffusion-metaflow","last_synced_at":"2025-10-18T17:10:02.613Z","repository":{"id":93794726,"uuid":"529342906","full_name":"outerbounds/diffusion-metaflow","owner":"outerbounds","description":"Running Stable Diffusion with Metaflow","archived":false,"fork":false,"pushed_at":"2024-01-30T22:06:14.000Z","size":4062,"stargazers_count":33,"open_issues_count":2,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-02T04:23:32.410Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/outerbounds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-08-26T17:10:07.000Z","updated_at":"2024-04-24T10:15:51.000Z","dependencies_parsed_at":"2024-01-30T22:45:35.751Z","dependency_job_id":null,"html_url":"https://github.com/outerbounds/diffusion-metaflow","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outerbounds%2Fdiffusion-metaflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outerbounds%2Fdiffusion-metaflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outerbounds%2Fdiffusion-metaflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outerbounds%2Fdiffusion-metaflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/outerbounds","download_url":"https://codeload.github.com/outerbounds/diffusion-metaflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250328593,"owners_count":21412648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T02:29:45.227Z","updated_at":"2025-10-18T17:10:02.453Z","avatar_url":"https://github.com/outerbounds.png","language":"Jupyter Notebook","funding_links":[],"categories":["Examples \u0026 Tutorials"],"sub_categories":[],"readme":"# Run Stable Diffusion With Metaflow 👋\n\nThis repository offers you a framework to create massive amounts of AI-generated images using the Stable Diffusion model.\nThe Stable Diffusion model is integrated into a Metaflow workflow that will help you scale horizontally or vertically to quickly produce as many images as you need. To run the code in this repository you will need access to a Metaflow deployment configured with S3 storage. If you want to learn more about Metaflow or need help getting set up, find us on [Slack](http://slack.outerbounds.co/)!\n\n![](/images/einstein_grid.png)\n\n\u003cp align = \"center\"\u003e\nStable Diffusion Intepretations of Einstein\n\u003c/p\u003e\n\n# Operate Metaflow on AWS Infrastructure\nBefore running the flow ensure that Metaflow-related infrastructure is [deployed](https://outerbounds.com/docs/aws-deployment-guide/) and [configured](https://outerbounds.com/docs/configure-metaflow/) on your AWS account and GPUs are configured for the compute environment (AWS Batch / EKS).\n\nIf you don't have infrastructure setup, you can set it up with this [cloudformation template](https://github.com/outerbounds/metaflow-tools/blob/master/aws/cloudformation/metaflow-cfn-template.yml). To deploy the GPU infrastructure on AWS, change the [ComputeEnvInstanceTypes](https://github.com/outerbounds/metaflow-tools/blob/d0da1fa4f9aa6845f8091d06a1b7a99962986c98/aws/cloudformation/metaflow-cfn-template.yml#L42) in the Cloudformation template or the Cloudformation UI. More detailed instructions on setting up infrastructure can be found [here](https://outerbounds.com/docs/cloudformation/).\n\n\n# Install Dependencies\n\n## Use `env.yml` with `conda`\n\nWe have included a conda environment in the form of a `env.yml` file for you to use. You can install and activate the environment by running the following commands from your terminal:\n```\nconda install mamba -n base -c conda-forge\nmamba env create -f env.yml\nconda activate meta-diffusion\n```\n\n## Use `requirements.txt` with `venv`\nIf you prefer to use [venv](https://docs.python.org/3/library/venv.html) you can create and activate a new environment by running the following commands from your terminal:\n```\npython venv -m ./meta-diffusion\nsource ./meta-diffusion/bin/activate\n```\nNote if you get an error installing the `transformers` library, you may need to install the [Rust compiler](https://rustup.rs/). You can do so like:\n```\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n```\n\n# Run the Code\nBefore running the flow ensure you have the necessary AWS infrastructure setup for Metaflow. These flows require S3 and GPU/s.\n\n\n## Step 1 : Download the Stable Diffusion Huggingface model\n- Ensure that you have signed the waiver for [CompVis/stable-diffusion-v-1-4-original](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original) model on the Huggingface hub.\n- Create a [Huggingface hub access token](https://huggingface.co/docs/hub/security-tokens)\n- Run the below command after replacing `\u003cmyhuggingfacetoken\u003e` with the Huggingface hub token created in the previous step. Run this command only once to download the model to the local machine.\n    ```sh\n    HF_TOKEN=\u003cmyhuggingfacetoken\u003e python model_download.py\n    ```\n\n## Step 2: Run Metaflow Flows\n\n\n### ⭐ Generate Images from a Simple Prompt ⭐\n**Source File** : [meta_diffusers_text.py](./meta_diffusers_text.py)\n\n\n**Run Command** :\n```sh\npython meta_diffusers_text.py run \\\n    --max-parallel 10 \\\n    --config-file ./text_config.yaml\n```\n\nThe schema of the [text-config.yaml](./text_config.yaml) can be found the [config.py](./config.py) file.\n\n**Options**:\n```\nOptions:\n  --config-file FILEPATH    experiment config file path\n  --config JSON             experiment config\n  --max-parallel INTEGER    This parameter will limit the amount of\n                            parallelisation we wish to do. Based on the value\n                            set here, the foreach will fanout to that many\n                            workers.  [default: 1]\n\n  --local-model-path TEXT   Path of local model to use instead of the one in\n                            S3\n```\n\n**Running Locally** : To run this flow locally, ensure that you have installed the `requirements.txt` file and commented the `@kubernetes` decorator in the [flow file](./meta_diffusers_text.py).\n\n\n### ⭐ Generate Many Images with Diverse Styles ⭐\n**Source File** : [meta_dynamic_prompts.py](./meta_dynamic_prompts.py)\n\n**Run Command** :\n```sh\npython meta_dynamic_prompts.py run --config-file ./style_config.yaml\n```\nThe schema of the [style_config.yaml](./style_config.yaml) can be found the [config.py](./config.py) file.\n\n**Options**:\n```\nOptions:\n  --config-file FILEPATH     experiment config file path\n  --config JSON              experiment config\n  --images-per-card INTEGER  Maximum number of images to show per @card\n                             [default: 10]\n```\n\n**Running Locally** : To run this flow locally, ensure that you have installed the `requirements.txt` file and commented the `@kubernetes` decorator in the [flow file](./meta_dynamic_prompts.py).\n\n\n### ⭐ Generate Videos from a Custom Prompt ⭐\n\n**Source File** : [text_to_video_flow.py](./text_to_video_flow.py)\n\n**Run Command** :\n```sh\npython text_to_video_flow.py --package-suffixes .yaml run --config-file ./video_config.yaml\n```\nThe schema of the [video_config.yaml](./video_config.yaml) can be found the [config.py](./config.py) file.\n\n**Extract Videos Post Completion**\n```python\nfrom metaflow import Flow, namespace\nimport os\nfrom model_store import ModelStore\nnamespace(None)\nflow = Flow(\"TextToVideo\")\nrun = flow.latest_successful_run\nstore = ModelStore.from_path(run[\"generate_video_from_images\"].task.pathspec)\nstore.download(\"final_render\",\"final_render\")\n```\n\n### ⭐⭐⭐ Generate a Cross Product of Videos from a Set of Custom Prompts ⭐⭐⭐\n**Source File** : [text_to_video_foreach_flow.py](./text_to_video_foreach_flow.py)\n\n**Run Command** :\n```sh\npython text_to_video_foreach_flow.py --package-suffixes .yaml run --config-file style_video.yaml\n```\nThe schema of the [video_config_foreach.yaml](./video_config_foreach.yaml) can be found the [config.py](./config.py) file.\n\n**Extract Videos Post Completion**\n```python\nfrom notebook_utils import download_foreach_run_videos\ndownload_foreach_run_videos(run_id='\u003cYOUR RUN ID\u003e')\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fouterbounds%2Fdiffusion-metaflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fouterbounds%2Fdiffusion-metaflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fouterbounds%2Fdiffusion-metaflow/lists"}