Pages

Sunday, December 22, 2024

Generative AI - Oracle Linux Setup

The latest NVIDIA Windows GPU Driver will fully support WSL 2.
https://us.download.nvidia.com/Windows/561.09/561.09-notebook-win10-win11-64bit-international-dch-whql.exe

In NVIDIA Control Panel, go to Help > System Information
In the Components tab, look for the CUDA driver entry for CUDA version.

3D Settings → Manage 3D Settings.
Change the CUDA System Memory Fallback to Driver default

Ensure the latest kernel.
PS C:\Users\user1> wsl cat /proc/version
Linux version 5.15.167.4-microsoft-standard-WSL2 (root@f9c826d3017f) (gcc (GCC) 11.2.0, GNU ld (GNU Binutils) 2.37) #1 SMP Tue Nov 5 00:21:55 UTC 2024

PS C:\Users\user1> nvidia-smi --version

Login Oracle Linux VM
PS C:\Users\user1> OracleLinux91

$ sudo dnf install module-init-tools g++ git unzip nvtop
$ sudo dnf update --refresh
$ sudo dnf clean all
$ sudo dnf list --extras
$ sudo dnf install python3.12 python3.12-devel python3.12-pip
$ sudo ln -s /usr/bin/python3.12 /usr/bin/python
$ sudo ln -s /usr/bin/pip3.12 /usr/bin/pip
$ python -m pip install --upgrade pip wheel setuptools lark torchprofile
$ python --version
$ python -m pip --version

Enable NVIDIA GPU Acceleration
---------------------------------------------
Download CUDA Toolkit at https://developer.nvidia.com/cuda-downloads
Install CUDA Toolkit. Add CUDA directory to PATH.
$ wget  https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda_12.4.1_550.54.15_linux.run
$ sudo sh cuda_12.4.1_550.54.15_linux.run
Please make sure that
 -  PATH includes /usr/local/cuda/bin
 -  add /usr/local/cuda/lib64 to /etc/ld.so.conf and run ldconfig as root

Download cuDNN 9.7.0 at https://developer.nvidia.com/cudnn-downloads
$ wget https://developer.download.nvidia.com/compute/cudnn/9.7.0/local_installers/cudnn-local-repo-rhel9-9.7.0-1.0-1.x86_64.rpm
$ sudo rpm -i cudnn-local-repo-rhel9-9.7.0-1.0-1.x86_64.rpm
$ sudo dnf clean all
$ sudo dnf -y install cudnn
$ sudo dnf -y install cudnn-cuda-12

Install pytorch with the correct CUDA compiled version. 
$ python -m pip install torch torchvision torchaudio torchao xformers --index-url https://download.pytorch.org/whl/cu126

Python Virtual Environment
--------------------------------------
$ python -m venv comfy_env
Activate a virtual environment
$ source comfy_env/bin/activate
(comfy-env) $ python -m pip list
(comfy-env) $ python -m pip install --upgrade pip
(comfy-env) $ python -m pip install wheel setuptools

diffusers[torch]
accelerate>=0.26


ComfyUI Manager
------------------------
(comfy_env) $ git clone https://github.com/comfyanonymous/ComfyUI.git

Setup essential nodes using git repos into ComfyUI/custom_nodes
(comfy-env) $ git clone https://github.com/Comfy-Org/ComfyUI-Manager.git ComfyUI/custom_nodes/ComfyUI-Manager
Install the dependencies.
(comfy_env) $ python -m pip install -r ComfyUI/requirements.txt
(comfy_env) $ git clone https://github.com/Efficient-Large-Model/ComfyUI_ExtraModels.git ComfyUI/custom_nodes/ComfyUI_ExtraModels

Display all of the packages installed in the virtual environment
(comfy-env) $ python -m pip list

export CUDA_VISIBLE_DEVICES=0
export PYTORCH_ALLOC_CONF=garbage_collection_threshold:0.9,max_split_size_mb:512,expandable_segments:True
export CUDA_LAUNCH_BLOCKING=1     --> Debugging

Launch comfyUI
(comfy_env) $ python ComfyUI/main.py --disable-cuda-malloc --gpu-only --disable-smart-memory &

Starting server

To see the Web UI go to: http://127.0.0.1:8188

Check comfyui.log for any errors. Adding --gpu-only will fix the below error in KSampler.
!!! Exception during processing !!! Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

NVIDIA Control Panel > Manage 3D Settings > Global Settings
Power management mode Prefer maximum performance
[Crystools ERROR] Monitor of GPU is turning off (not on UI!)

(Optional) Modify security level to install PIP packages & Git URL in ComfyUI-Manager
ComfyUI/custom_nodes/ComfyUI-Manager/config.ini
security_level = weak

Resource Monitor
------------------------
Select Custom Nodes Manager button
Install crystools by entering crys in search bar.
In Settings, Click on Comfy and then close the message if it is not showing up.

Sana_CogVideoX
------------------------
Install diffusers>=0.32.0.dev to make the SanaPipeline and SanaPAGPipeline available.
(comfy_env) $ pip install git+https://github.com/huggingface/diffusers
pip install --upgrade diffusers[torch]
install these packages to fix cv2 and compile errors.
(comfy_env) $ pip install triton opencv-python-headless
(comfy_env) $ pip cache purge

Select Custom Nodes Manager button
Install Extra Models for ComfyUI by entering extra models in search bar.
Note : To download models correctly. 
(comfy_env) $ git -C ComfyUI/custom_nodes/ComfyUI_ExtraModels pull

Install ComfyUI-CogVideoXWrapper by entering cogvideo in the search bar
Install ComfyUI-VideoHelperSuite by entering videohelp in the search bar
Install ComfyUI-KJNodes by entering kjnodes in the search bar

NOTE : All json files update transformers and diffuser version 
              Remove fp16 in model file names

The original weights can be found under https://huggingface.co/collections/Efficient-Large-Model/sana-673efba2a57ed99843f11f9e

Make sure to set variant and torch_dtype in diffusers pipelines to the desired precision.
Use the "unsloth--gemma-2-2b-it-bnb-4bit" LLM.
Automatically downloaded into ComfyUI/models/text_encoders/models--unsloth--gemma-2-2b-it-bnb-4bit


$ sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %{rhel}).noarch.rpm
sudo dnf config-manager --set-disabled epel
sudo dnf --enablerepo=epel -y install nvtop
sudo dnf remove epel-release

VAE
https://huggingface.co/Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers/resolve/main/vae/
diffusion_pytorch_model.bf16.safetensors
config.json

Download Workflows
wget https://raw.githubusercontent.com/NVlabs/Sana/refs/heads/main/asset/docs/ComfyUI/Sana_FlowEuler.json -O ComfyUI/custom_nodes/ComfyUI_ExtraModels/Sana/Sana_FlowEuler.json
$ wget https://raw.githubusercontent.com/NVlabs/Sana/refs/heads/main/asset/docs/ComfyUI/Sana_CogVideoX.json -O ComfyUI/custom_nodes/ComfyUI_ExtraModels/Sana/Sana_CogVideoX.json
wget https://github.com/user-attachments/files/18027854/SanaV1.json -O ComfyUI/custom_nodes/ComfyUI_ExtraModels/Sana/SanaV1.json
wget https://comfyuiblog.com/wp-content/uploads/2024/09/workflow-54.json

Open these workflows and Install Missing Custom Nodes

Finally, run the workflow by clicking on "Queue Prompt" button. The models will be downloaded automatically.

gradio
---------
$ pip install gradio gradio_imageslider python-dotenv comfydeploy

Create a .env file in the project root with the following content:
API_KEY=your_comfydeploy_api_key
DEPLOYMENT_ID=your_deployment_id

$ gradio deploy

Whisper
------------
Speach recognition model
Select Custom Nodes Manager button
Install ComfyUI-IF_AI_WishperSpeechNode by entering Whisper in search bar

Models
https://huggingface.co/WhisperSpeech/WhisperSpeech/resolve/main/s2a-q4-tiny-en%2Bpl.model
https://huggingface.co/WhisperSpeech/WhisperSpeech/resolve/main/t2s-small-en%2Bpl.model


Load this workflow into ComfyUI & install missing custom nodes
https://raw.githubusercontent.com/jarvislabsai/comfyui_workflows/refs/heads/main/if_ai_speech.json

MMAudio
-------------
$ cd custom_nodes && git clone https://github.com/kijai/ComfyUI-MMAudio.git && cd ..
$ pip install -r custom_nodes\ComfyUI-MMAudio\requirements.txt

Models
$ cd models/mmaudio
$ wget https://huggingface.co/Kijai/MMAudio_safetensors/blob/main/mmaudio_large_44k_v2_fp32.safetensors
$ wget https://huggingface.co/Kijai/MMAudio_safetensors/blob/main/mmaudio_vae_44k_fp16.safetensors
$ wget https://huggingface.co/Kijai/MMAudio_safetensors/blob/main/mmaudio_synchformer_fp16.safetensors

Apple Clip
$ cd models/mmaudio/apple/DFN5B-CLIP-ViT-H-14-384
$ git close https://huggingface.co/apple/DFN5B-CLIP-ViT-H-14-378/tree/main

Nvidia bigvganv2 (used with 44k mode)
$ cd models/mmaudio/nvidia/bigvgan_v2_44khz_128band_512x
$ git clone https://huggingface.co/nvidia/bigvgan_v2_44khz_128band_512x/tree/main


To leave a virtual environment
(venv) $ deactivate

$ kill `ps -ef | grep "python main.py" | head -1 | awk '{print $2}'`

To delete virtual environment
$ rm -rf <venv>

(Optional) Hugging Face
--------------------------------
Login at https://huggingface.co
Click on Access Tokens
Create new token with Token Type as Read
Provide Token name and click on Create token

$ git config --global credential.helper store
$ huggingface-cli login
Enter your token :
Add token as git credential? (Y/n) Y
Your token has been saved to ~/.cache/huggingface/token

$ wget --header="Authorization: Bearer `cat ~/.cache/huggingface/token`" https://huggingface.co/google/gemma-7b-it-pytorch/resolve/main/gemma-7b-it.ckpt

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

Commands
----------------
Test if cuda is recognized.
$ python -c "import torch; print(torch.rand(2,3).cuda())"
if you get a tensor back, you are ready to go.
If more than 1 card installed, check the count.
$ python -c "import torch; print(torch.cuda.device_count())"

Allocated memory
$ python -c "import torch; print(torch.cuda.memory_allocated())"
Cached memory
$ python -c "import torch; print(torch.cuda.memory_reserved())"

$ python -c "import torch; torch.cuda.empty_cache()"
$ python -c "import torch; torch.cuda.memory_summary()"

nvtop
$ sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %{rhel}).noarch.rpm
$ sudo dnf install nvtop
$ sudo dnf config-manager --set-disabled epel
$ sudo dnf config-manager --set-disabled epel-cisco-openh264


write scenes in chatgpt.com
generate prompts for each scene... Narration (Animation Prompt).. convert to telugu, Image Prompt
text to image Leonardo.ai or PicLumen
image to video, motion prompt Hailuo AI or KlingAI or wan.video(install)
text to speech ..dialogues text  Narration...select voice Elevenlabs or OpenAI.fm
Narration... text to speech select voice speed pitch volume Hailuo AI
lip-sync.. upload video and audio....with dialogue  Magic Hour or Wav2Lip
Editing DaVinci

gemini.google.com
chat.qwen.ai
aistudio.google.com
dreamina.capcut.com

google whisk new image from existing image