jy0205 / Pyramid-Flow

Code of Pyramidal Flow Matching for Efficient Video Generative Modeling
https://pyramid-flow.github.io/
MIT License
2.5k stars 245 forks source link

add seed PLEASE!! #91

Open ptits opened 1 month ago

ptits commented 1 month ago

for tests it is so important

add seed to gradio demo and all other calls

I did it myself - just added this code to my gradio :

use it if needed - I am not familiar with pull requests

def generate_text_to_video(prompt, temp, guidance_scale, video_guidance_scale, text_seed, steps, video_steps): set_seed(int(text_seed)) with torch.no_grad(), torch.cuda.amp.autocast(enabled=True if model_dtype != 'fp32' else False, dtype=torch_dtype): ...... ......

###################################################### def set_seed(seed: int):

Set seed for Python's built-in random module

random.seed(seed)

# Set seed for NumPy
np.random.seed(seed)

# Set seed for PyTorch (both CPU and GPU if available)
torch.manual_seed(seed)

# If you are using GPUs, set the seed for all GPUs
if torch.cuda.is_available():
    torch.cuda.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)  # for multi-GPU setups

# Ensure deterministic behavior in cuDNN (for GPU operations)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

# This ensures that operations like `torch.rand()` or `torch.randn()` return consistent results
os.environ['PYTHONHASHSEED'] = str(seed)
feifeiobama commented 1 month ago

We've labeled the issue so that users with such a need can come in and check your code. However, we may not merge this into the main branch, as torch.backends.cudnn.benchmark = False will slow down the generation process. That being said, thanks for the contribution!

ptits commented 1 month ago

I have cut the code to:

torch.manual_seed(seed)
# If you are using GPUs, set the seed for all GPUs
if torch.cuda.is_available():
    torch.cuda.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)  # for multi-GPU setups

And fixed SEED still working fine for my tests

please, add seed parameter