Skip to content
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

Image Annotation Moderation and FLUX Model Integration #65

Merged
merged 53 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2f6160e
adding blackforest labs models
dylanuys Aug 12, 2024
2adec09
temporarily disabling real image challenges to maximize data production
dylanuys Aug 12, 2024
c81a4a7
adding cpu offload
dylanuys Aug 12, 2024
b3b4f60
adding arg for flux generation
dylanuys Aug 12, 2024
aaaedd5
calling flux generation with new args in constants.py
dylanuys Aug 12, 2024
8af1cc6
pulling in latest from main
dylanuys Aug 20, 2024
e5e9f60
constants update for flux mirror gen
dylanuys Aug 20, 2024
fa19189
adding cache dir to model loads
dylanuys Aug 20, 2024
4bec465
temp notebooks for flux tests
dylanuys Aug 20, 2024
51d39f8
typo
dylanuys Aug 20, 2024
31ccd59
updating guidance_scale
dylanuys Aug 21, 2024
02dcea8
Added Meta's Llama-3.1-8B-Instruct model for annotation moderation.
benliang99 Aug 22, 2024
f6de46e
Upgraded BLIP2 model to 6.7B param version
benliang99 Aug 23, 2024
ddc06ad
Replaced Llama-3.1-8B-Instruct model with Unsloth's ungated version.
benliang99 Aug 23, 2024
e128200
Updated requirements with Unsloth model dependency.
benliang99 Aug 23, 2024
cf16da4
Clear image generation annotation models from GPU after generating im…
benliang99 Aug 24, 2024
bdb3693
Fixed usage of generation args, updated image generation helper funct…
benliang99 Aug 24, 2024
d6199a9
Added gpu-specific diffusion model loading for parallelization
benliang99 Sep 9, 2024
cd5b897
Fixed docstring indent
benliang99 Sep 9, 2024
aed5346
Added gpu specification for synthetic image generation
benliang99 Sep 9, 2024
160dd66
Added dataset gen GPU delegation shell script and SDXL to constants
benliang99 Sep 17, 2024
2f7fab5
Removed HF token
benliang99 Sep 17, 2024
7ea024d
Fixed specification of torch.dtype for SDXL
benliang99 Sep 17, 2024
56b2cec
Reformatting empty lines, added stress test script.
benliang99 Sep 18, 2024
46b2cdd
Added temporary stress testing prints
benliang99 Sep 18, 2024
f7ed8f3
Added all diffusion models and updated generate args
benliang99 Sep 18, 2024
585f42f
Added float16 tensor tflop specs metric
benliang99 Sep 19, 2024
3e5128f
Set default GPU for diffusion models to cuda if no gpu_id specified. …
benliang99 Sep 19, 2024
46fcaef
Merged with testnet
benliang99 Sep 19, 2024
c1e2ac9
Reverted merge
benliang99 Sep 19, 2024
75981ca
Merge branch 'main' into llm-annotation-moderation
benliang99 Sep 23, 2024
949df9b
Merged Main, Testnet into branch
benliang99 Sep 23, 2024
be629c4
Removed unnecessary imports
benliang99 Sep 23, 2024
b220f12
Added diffusion model verification/loading at the end of validator se…
benliang99 Sep 23, 2024
6285d92
Added validator model verification script for initial model download …
benliang99 Sep 23, 2024
8c51b22
Fixed typo.
benliang99 Sep 23, 2024
2fd800b
Added check for model presence in cache
benliang99 Sep 23, 2024
8e3c6bc
Reinstated necessary pipeline imports
benliang99 Sep 23, 2024
4cb39cc
PEP8 class spacing
benliang99 Sep 23, 2024
8ea2b54
Notebook cleanup.
benliang99 Sep 23, 2024
a4204f8
ImageAnnotationGenerator doc/class strings
benliang99 Sep 23, 2024
4aaf558
SyntheticImageGenerator docstring updates
benliang99 Sep 24, 2024
a90c2c6
Merge with testnet
benliang99 Oct 2, 2024
1c59491
Removed legacy (unused) directory
benliang99 Oct 2, 2024
b31b17c
Renamed and moved validator model verification to bitmind/validator/,…
benliang99 Oct 2, 2024
6cadbbd
Added validator-specific unit testing
benliang99 Oct 3, 2024
e817257
Added unit test for generating images. Added PEP8 docstrings.
benliang99 Oct 3, 2024
0625df5
Merge testnet into llm-annotation-moderation
benliang99 Oct 15, 2024
9b4c612
Correct WANDB_PROJECT constantexit
benliang99 Oct 15, 2024
fc1d817
Update setup fields
benliang99 Oct 15, 2024
17ee8f5
Fixed axon undefined
benliang99 Oct 15, 2024
fa90608
Added conditional cuda usage
benliang99 Oct 15, 2024
d2cf985
Merge remote-tracking branch 'origin/testnet' into llm-annotation-mod…
benliang99 Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autoupdate_validator_steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
echo $CONDA_PREFIX
$CONDA_PREFIX/bin/pip install -e .
$CONDA_PREFIX/bin/python bitmind/download_data.py
$CONDA_PREFIX/bin/python bitmind/validator/verify_models.py
echo "Autoupdate steps complete :)"
46 changes: 42 additions & 4 deletions bitmind/constants.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import os
import torch


WANDB_PROJECT = 'bitmind-subnet'
WANDB_ENTITY = 'bitmindai'

DATASET_META = {
"real": [
{"path": "bitmind/bm-real"}
{"path": "bitmind/bm-real"},
{"path": "bitmind/open-images-v7"},
{"path": "bitmind/celeb-a-hq"},
{"path": "bitmind/ffhq-256"},
{"path": "bitmind/MS-COCO-unique-256"}
],
"fake": [
{"path": "bitmind/bm-realvisxl"},
Expand Down Expand Up @@ -48,19 +53,36 @@
{
"path": "stabilityai/stable-diffusion-xl-base-1.0",
"use_safetensors": True,
"torch_dtype": torch.float16,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torch_dtype is no longer hardcoded, so it must be specified in the pipeline / DIFFUSER_ARGS.

"variant": "fp16",
"pipeline": "StableDiffusionXLPipeline"
},
{
"path": "SG161222/RealVisXL_V4.0",
"use_safetensors": True,
"torch_dtype": torch.float16,
"variant": "fp16",
"pipeline": "StableDiffusionXLPipeline"
},
{
"path": "Corcelio/mobius",
"use_safetensors": True,
"torch_dtype": torch.float16,
"pipeline": "StableDiffusionXLPipeline"
},
{
"path": 'black-forest-labs/FLUX.1-dev',
"use_safetensors": True,
"torch_dtype": torch.bfloat16,
"generate_args": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguments decided based on experimental generation latencies.

"guidance_scale": 2,
"num_inference_steps": {"min": 50, "max": 125},
"generator": torch.Generator("cuda" if torch.cuda.is_available() else "cpu"),
"height": [512, 768],
"width": [512, 768]
},
"enable_cpu_offload": False,
"pipeline": "FluxPipeline"
}
]
}
Expand All @@ -69,16 +91,30 @@

TARGET_IMAGE_SIZE = (256, 256)

PROMPT_TYPES = ('random', 'annotation')
PROMPT_TYPES = ('random', 'annotation', 'none')

PROMPT_GENERATOR_ARGS = {
m['model']: m for m in VALIDATOR_MODEL_META['prompt_generators']
}

PROMPT_GENERATOR_NAMES = list(PROMPT_GENERATOR_ARGS.keys())

# args for .from_pretrained
DIFFUSER_ARGS = {
m['path']: {k: v for k, v in m.items() if k != 'path' and k != 'pipeline'}
m['path']: {
k: v for k, v in m.items()
if k not in ('path', 'pipeline', 'generate_args', 'enable_cpu_offload')
} for m in VALIDATOR_MODEL_META['diffusers']
}

GENERATE_ARGS = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New field for generation arguments, which FLUX-1.dev can utilize.

m['path']: m['generate_args']
for m in VALIDATOR_MODEL_META['diffusers']
if 'generate_args' in m
}

DIFFUSER_CPU_OFFLOAD_ENABLED = {
m['path']: m.get('enable_cpu_offload', False)
for m in VALIDATOR_MODEL_META['diffusers']
}

Expand All @@ -88,4 +124,6 @@

DIFFUSER_NAMES = list(DIFFUSER_ARGS.keys())

IMAGE_ANNOTATION_MODEL = "Salesforce/blip2-opt-2.7b-coco"
IMAGE_ANNOTATION_MODEL = "Salesforce/blip2-opt-6.7b-coco"

TEXT_MODERATION_MODEL = "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit"
Empty file removed bitmind/miner/__init__.py
Empty file.
13 changes: 6 additions & 7 deletions bitmind/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
import base64
import torch

def b64_encode(image):
if isinstance(image, torch.Tensor):
image = transforms.ToPILImage()(image.cpu().detach())
image_bytes = BytesIO()
image.save(image_bytes, format="JPEG")
return base64.b64encode(image_bytes.getvalue())

def prepare_image_synapse(image: Image):
"""
Expand All @@ -43,7 +37,12 @@ def prepare_image_synapse(image: Image):
Returns:
ImageSynapse: An instance of ImageSynapse containing the encoded image and a default prediction value.
"""
b64_encoded_image = b64_encode(image)
if isinstance(image, torch.Tensor):
image = transforms.ToPILImage()(image.cpu().detach())

image_bytes = BytesIO()
image.save(image_bytes, format="JPEG")
b64_encoded_image = base64.b64encode(image_bytes.getvalue())
return ImageSynapse(image=b64_encoded_image)


Expand Down
16 changes: 1 addition & 15 deletions bitmind/synthetic_image_generation/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@

# Synthetic Image Generation

This folder contains files for the implementation of a joint vision-to-language and text-to-image model system that generates highly diverse and realistic images for deepfake detector training.

**test_data/:**

Default output directory for real-image-to-annotation and annotation-to-synthetic-image pipelines in the associated notebooks.

Notebooks:

**real_image_to_text_annotation.ipynb :**

Pipeline for real image dataset to text caption dataset generation. Contains function that generates subdirectories of annotations for each real image dataset. Annotations are formatted as JSONs with captions (Strings) of images. The filename of the JSONs correspond to the image index in the associated dataset dictionary.

**text_annotation_to_synthetic_image.ipynb :**

Pipeline for text annotation to synthetic image dataset generation.
This folder contains files for the implementation of a joint vision-to-language and text-to-image model system that generates highly diverse and realistic images for deepfake detector training and Subnet 34 validating.
76 changes: 0 additions & 76 deletions bitmind/synthetic_image_generation/combine_datasets.py

This file was deleted.

Loading
Loading