{"id":13491944,"url":"https://github.com/camenduru/train-text-to-image-tpu-tutorial","last_synced_at":"2025-05-06T00:01:54.568Z","repository":{"id":65374986,"uuid":"591131699","full_name":"camenduru/train-text-to-image-tpu-tutorial","owner":"camenduru","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-26T08:29:48.000Z","size":66,"stargazers_count":22,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-05T00:11:37.405Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/camenduru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":"camenduru","open_collective":null,"ko_fi":"camenduru","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-01-20T01:32:57.000Z","updated_at":"2025-02-06T02:46:43.000Z","dependencies_parsed_at":"2024-01-16T09:01:54.064Z","dependency_job_id":"28012228-4ac8-4ccf-92f7-fdbed996846c","html_url":"https://github.com/camenduru/train-text-to-image-tpu-tutorial","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/camenduru%2Ftrain-text-to-image-tpu-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camenduru%2Ftrain-text-to-image-tpu-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camenduru%2Ftrain-text-to-image-tpu-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camenduru%2Ftrain-text-to-image-tpu-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/camenduru","download_url":"https://codeload.github.com/camenduru/train-text-to-image-tpu-tutorial/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252596399,"owners_count":21773844,"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-07-31T19:01:01.768Z","updated_at":"2025-05-06T00:01:54.498Z","avatar_url":"https://github.com/camenduru.png","language":"Python","funding_links":["https://patreon.com/camenduru","https://ko-fi.com/camenduru"],"categories":["Python"],"sub_categories":[],"readme":"🐣 Please follow me for new updates https://twitter.com/camenduru \u003cbr /\u003e\n🔥 Please join our discord server https://discord.gg/k5BwmmvJJU \u003cbr /\u003e\n🥳 Please join my patreon community https://patreon.com/camenduru \u003cbr /\u003e\n\nThis repo contains all codes and commands used in `train text to image with tpu tutorial` https://youtu.be/NGta-t4BoLY\n\n## Prepare TPU VM\nuse with 🐧 linux or linux inside windows (wsl)\n\nhttps://console.cloud.google.com\n\n```sh\necho \"deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main\" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list\ncurl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -\nsudo apt-get update \u0026\u0026 sudo apt-get install google-cloud-cli\ngcloud init\n```\n\n```sh\ngcloud alpha compute tpus tpu-vm ssh node-1 --zone us-central1-f\n```\n\n```py\npip install -U zipp \"jax[tpu]==0.3.23\" -f https://storage.googleapis.com/jax-releases/libtpu_releases.html packaging flax==0.6.1 chex==0.1.5 orbax==0.0.13 numpy diffusers==0.10.0 transformers piexif fold_to_ascii discord ftfy dill urllib3 datasets importlib-metadata accelerate==0.16.0 OmegaConf wandb==0.13.4 optax torch torchvision modelcards pytorch_lightning protobuf==3.20.* tensorboard markupsafe==2.0.1 gradio\n\nsudo apt install git-lfs\n```\n\n```sh\nmkdir tpu\ncd tpu\nmkdir train\ncd train\n```\n\n```sh\nwget https://raw.githubusercontent.com/camenduru/train-text-to-image-tpu-tutorial/main/train_text_to_image_flax.py\n```\n\n```sh\ntmux\n```\n\n## Prepare Dataset\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/train-text-to-image-tpu-tutorial/blob/main/prepare_dataset_colab.ipynb)\n\n\n## Train\n\n```py\npython3 train_text_to_image_flax.py \\\n  --pretrained_model_name_or_path=\"flax/sd15-non-ema\" \\\n  --dataset_name=\"camenduru/test\" \\\n  --resolution=512 \\\n  --mixed_precision=\"bf16\" \\\n  --train_batch_size=1 \\\n  --num_train_epochs=650 \\\n  --learning_rate=1e-6 \\\n  --max_grad_norm=1 \\\n  --output_dir=\"test\" \\\n  --report_to=\"wandb\"\n```\n\n## Push Trained model to 🤗\n\n```sh\nwget https://raw.githubusercontent.com/camenduru/train-text-to-image-tpu-tutorial/main/push.py\npython3 push.py\n```\n\n## Convert Flax model to PyTorch\nhttps://huggingface.co/spaces/camenduru/converter\n\n## Test Flax model or PyTorch model\nhttps://github.com/camenduru/stable-diffusion-diffusers-colab\n\n## Outputs\nhttps://huggingface.co/camenduru/tpu-train-tutorial-flax \u003cbr /\u003e\nhttps://huggingface.co/camenduru/tpu-train-tutorial-pt\n\n## YouTube Live VOD\nhttps://youtu.be/NGta-t4BoLY\n\n## Main Repo ♥\nhttps://github.com/huggingface/diffusers\n\n## Scripts From ♥\nhttps://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_flax.py\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamenduru%2Ftrain-text-to-image-tpu-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcamenduru%2Ftrain-text-to-image-tpu-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamenduru%2Ftrain-text-to-image-tpu-tutorial/lists"}