huggingface / huggingface/fuego
Handle "store_true" bool flags more elegantly
- Dominant language
- Python
- Stars
- 87
- Forks
- 9
- Avg merge
- 6m
- Merged PRs (30d)
- 1
Description
Right now, bool args are converted and passed to the script like `--do_the_thing True` if you passed `do_the_thing=True` as a kwarg to `run`. Sometimes, like in the case of `action='store_true'`, argparse doesn't like this. It also doesn't like `--do_the_thing=True` sometimes as well. Note I ran into this while running [this script](https://github.com/huggingface/diffusers/blob/8178c840f265d4bee91fe9cf9fdd6dfef091a720/examples/dreambooth/train_dreambooth_lora.py) from diffusers.
---
#### Reproducible Example
You'll need a local instance data dir with some images, and may want to update the instance prompt/validation prompt.
_**fuego_run.py**_
```python
from pathlib import Path
import fuego
base_model = 'stabilityai/stable-diffusion-2-1-base'
instance_data_dir = './rexxliferaj_images'
output_dir = './outputs'
instance_prompt = "a photo of sks rexxliferaj"
resolution = 512 # 768
gradient_accumulation = 1
learning_rate = 1e-4
n_steps = 1000
checkpointing_steps = 100
validation_prompt = "a photo of sks rexxliferaj at the Eiffel Tower"
validation_epochs = 100
seed = 42
fp16 = True
use_8bit_adam = True
use_wandb=False
space_url, dataset_url = fuego.run(
script=Path(__file__).parent / "run_lora_finetuning.py",
requirements_file=Path(__file__).parent / "requirements.txt",
delete_space_on_completion=False,
space_hardware="t4-small",
downgrade_hardware_on_completion=False,
# Kwargs
pretrained_model_name_or_path=base_model,
instance_data_dir=instance_data_dir,
output_dir=output_dir,
instance_prompt=instance_prompt,
resolution=resolution,
train_batch_size=1,
gradient_accumulation_steps=gradient_accumulation,
learning_rate=learning_rate,
lr_scheduler="constant",
lr_warmup_steps=0,
max_train_steps=n_steps,
checkpointing_steps=checkpointing_steps,
validation_prompt=validation_prompt,
validation_epochs=validation_epochs,
seed=seed,
mixed_precision="fp16" if fp16 else None,
use_8bit_adam=use_8bit_adam,
report_to="wandb" if use_wandb else "tensorboard",
)
print(f"Space: {space_url}")
print(f"Dataset: {dataset_url}")
```
**_requirements.txt_**
```
accelerate==0.15.0
bitsandbytes==0.36.0.post2
datasets==2.8.0
git+https://github.com/huggingface/diffusers@31be42209ddfdb69d9640a777b32e9b5c6259bf0#egg=diffusers
ftfy==6.1.1
gradio==3.16.2
huggingface-hub==0.12.0
Pillow==9.4.0
python-slugify==7.0.0
tensorboard==2.11.2
torch==1.13.1
torchvision==0.14.1
transformers==4.26.0
wandb==0.13.9
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the fuego.run call in fuego_run.py and reproduce the boolean-flag behavior using the provided example and requirements.txt. Trace how kwargs such as use_8bit_adam and fp16 become script arguments, then verify that store_true flags are accepted without an extra boolean value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100