scripts/generate_cards.py is the main entry point. This will
4 separate AIs contribute to the card design, so that certain attributes can be lifted out of scope from the main text training data.
nns/names* is an LSTM created for this project and trained to generate card names. This was trained both on all exisitng MTG card names as well as on a smattering of other words, phrases, and name-like strings. This increases the diversity of names outside of normal MTG card names.nns/main_text* is an LSTM created for this project and trained to generate all functional attributes and text of the cards. This was trained on select fields from all MTG cards (at time of training). This AI is whispered the names generated by the above AI during sampling.llm.A1SD.generate_cards.py, which pulls all the ingredients together to create new cards.scripts/generate_cards.py
python generate_cards.py --lstm_gpu 1 --names_nn ../nns/names_3 --main_text_nn ../nns/main_text_13 --flavor_nn timdettmers_guanaco-65b-merged --gpu-memory 23 --cpu-memory 250 --sd_nn "nov_mtg_art_v2_3.ckpt [76fcbf0ef5]" --outdir ../outputs --num_cards 10 --hr_upscale 2 --verbosity=9 --to_pdf
python generate_cards.py --help for more info on arguments*_cache) under the auto-generated output folder (eg ../outputs/00003_481992436), so the generator can be stopped and resumed without losing much via the --resume_folder ... argument. Also useful if it crashes for some inconsistent reason.stats.yaml in the output foldercard_data.yaml in the output folderprintable_cards.pdf) if you specify the --to_pdf arg| args | timing on the dev's machine | amount of data produced |
|---|---|---|
--hr_upscale 2 (all features enabled) | ~ 5-10 minutes per card | ~ 5 MB / card |
--no_flavor --hr_upscale 2 | ~ 2.5 cards / minute | ~ 4.5 MB / card |
--no_flavor | ~ 6.5 cards / minute | ~ 2.5 MB / card |
--no_flavor --no_art | ~ 10 cards / minute | ~ 250 KB / card |
--no_flavor --no_art --no_render | ~ 20 cards / minute | ~ 1.5 KB / card |
--to_pdf (ignoring other args + steps) | Adds ~ 20-40s per card, somehow this scales quadratically | roughly +50% |
python generate_cards.py --sd_nn "nov_mtg_art_v2_3.ckpt [76fcbf0ef5]" --verbosity=9 --outdir ../outputs --hr_upscale 2 --basic_lands "{'Plains':51, 'Island':51, 'Swamp':51, 'Mountain':51, 'Forest':51, 'Snow-Covered Plains':25, 'Snow-Covered Island':25, 'Snow-Covered Swamp':25, 'Snow-Covered Mountain':25, 'Snow-Covered Forest':25, 'Wastes':36}" --to_pdfgenerate_cards.py like normal plus args --no_flavor --no_art --no_render, so that only the text is generatedcard_data.yaml, and hand-modify the contents to your heart's desire. You can also delete cards entirely from the file.generate_cards.py like normal with --finish_yaml <yaml path>--resume_folder <folder path> (and specify the same args)Install NVidia CUDA toolkit version 11.8. (Trying newer versions may require manual customization of subtrees, especially torch-rnn which is no longer developed.)
A1SD/models/ldm/stable-diffusion-v1/. Git does not support large files (several GB), so these files are not committed to the repo.install_dir in webui.shCOMMANDLINE_ARGS in webui-user.sh based on your amount of ram, see docsbash webui.sh to finish setup
Running on local URL: http://127.0.0.1:7860)ctrl+c it to close the process for nowcd llmbash setup.sh
conda run -n llm python download-model.py timdettmers/guanaco-65b-merged (~160 GB)
server.py to finish setup
Running on local URL: )ctrl+c it to close the process for now~/torch and fiddle until it works. The order of these steps is critical. If you screw up, its often easier to rm -rf ~/torch and start over than try to recover.libhdf5-dev
deb [trusted=yes check-valid-until=no] http://dk.archive.ubuntu.com/ubuntu/ trusty main universe to /etc/apt/sources.listsudo apt updatesudo apt-get install libhdf5-dev==1.8.11*sudo apt-mark hold libhdf5-dev to pin versionconda env create -f environment-python.yaml. Use this enviropnment only for the preprocessing scriptgcc-6 and g++-6, since the older torch repo + cuda combination only works with this version
deb [trusted=yes] http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to /etc/apt/sources.listsudo apt updatesudo apt install gcc-6 g++-6gcc-6 and g++-6
sudo ln -s /usr/bin/gcc-6 /usr/local/cuda/bin/gccsudo ln -s /usr/bin/g++-6 /usr/local/cuda/bin/g++sudo ln -s -T /usr/local/cuda-11.8/lib64/libcublas.so /usr/lib/x86_64-linux-gnu/libcublas_device.sosudo add-apt-repository ppa:ubuntuhandbook1/ppa and sudo apt-get updategit config --global url."https://github.com/".insteadOf [email protected]git config --global url."https://".insteadOf git://pip install ipythonsudo apt-get purge cmakecd ~git clone https://github.com/Kitware/CMake.gitcd CMake./bootstrap; make; sudo make installbash install_torch.sh |& tee log-torch-install.txt. There will be several prompts.
sudo apt install expect to get unbuffer commandconda env create -f environment.yamlnltk language files
cd ~/nltk_datapython -c "import nltk; nltk.download('punkt')"AllPrintings.json from mtgjson website to raw_data_sources/.raw_data_sources/names.yaml and raw_data_sources/flavor.yaml manually with additional training databash rebuild_data_sources.sh |& tee log-data-build.txt in scripts/
Average chunk length for each AI to update constants in generate_cards.py -> LSTM_LEN_PER_MAIN_TEXT, LSTM_LEN_PER_NAME, and LSTM_LEN_PER_FLAVORLongest chunk length for each AI to set minimum -seq_length argument to train.luaTotal vocabulary size for each AI to set -wordvec_size argument to train.lua?scripts/encode.pyth train.lua -gpu 0 -input_h5 ../encoded_data_sources/names.h5 -input_json ../encoded_data_sources/names.json -checkpoint_name ../nns/names_3/checkpoint -rand_chunks_n_epochs 5 -checkpoint_n_epochs 100 -validate_n_epochs 10 -print_every 1 -num_layers 3 -rnn_sizes "200, 200, 200" -max_epochs 100000000 -batch_size 2000 -seq_length 150 -dropout 0.5 -learning_rate 0.02 -lr_decay_n_epochs 30 -lr_decay_factor 0.985 -wordvec_size 74th train.lua -gpu 0 -input_h5 ../encoded_data_sources/main_text.h5 -input_json ../encoded_data_sources/main_text.json -checkpoint_name ../nns/main_text_13/checkpoint -rand_chunks_n_epochs 1 -checkpoint_n_epochs 30 -validate_n_epochs 1 -print_every 1 -num_layers 4 -rnn_sizes "600, 600, 600, 600" -max_epochs 100000000 -batch_size 260 -seq_length 900 -dropout 0.5 -learning_rate 0.001 -lr_decay_n_epochs 10 -lr_decay_factor 0.99 -wordvec_size 122th train.lua -input_h5 ../encoded_data_sources/flavor.h5 -input_json ../encoded_data_sources/flavor.json -checkpoint_name ../nns/flavor_0/checkpoint -rand_chunks_n_epochs 1 -checkpoint_n_epochs 100 -validate_n_epochs 1 -print_every 1 -num_layers 3 -rnn_size 256 -max_epochs 100000000 -batch_size 200 -seq_length 500 -dropout 0.5 -learning_rate 0.002 -lr_decay_n_epochs 50 -lr_decay_factor 0.99CTRL+c to stop training when the AI is ready. Use scripts/plot_nn_loss.py to assess progress.th sample.lua -checkpoint ../nns/names_0/checkpoint_1001.000000.t7 -length 50. The main generator will use a similar command to sample the AIs when generating cards.raw_data_sources include user inputs for AI training data. These are processed into encoded_data_sources via rebuild_data_sources.sh, which utilizes scripts/encode.py and torch-rnn.nns contains trained text-based neural networkstorch-rnn contains code for training and sampling the text neural networksA1SD contains image generating neural networks and associated code.llm contains text generating neural networks and associated code.scripts contains the main generator entry point generate_cards.py as well as intermediary and utility scriptsoutputs contains rendered card images, card sheets, full text and stats yaml files, and cached intermediate stepsimage_templates contains template images for rendering the generated cardssetup.pywatch -n1 nvidia-smi to see GPU resource utilizationfind . -name "*.svg" | xargs inkscape --export-type=png --export-width=1000 --export-height=1000 --export-png-color-mode=RGBA_8 --batch-processpython plot_nn_loss.py --json_path nns/names_1/checkpoint_21.000000.jsonenvironment.yaml update the environment with conda deactivate && conda env remove --name mtg-ai-main && conda env create -f environment.yaml && conda activate mtg-ai-maingit remote add -f <name> <url>git subtree add --prefix <dir> <remote> <branch> --squashgit fetch <remote> <branch> and then git subtree pull --prefix <dir> <remote> <branch> --squashlr_lockout_zone parameter, which is the width and height of a box protruding into the lower right corner of hte text area, overwhich text should not be rendered. Implement "not rendering text in that area" by checking currently rendered line height and prospective width against the new constraints every time a rendered-text image is considered for addition to the current line.main_text and names instead of LSTMscard_data.yaml
card_data.yaml when its defined at time of file writing, and omit when its notnns_names attribute from the yaml, and repalce it with individual network name attributes (eg nn_names)to_tts_asset.py to format cards into sheets for upload to TTS
names_3 after removal of ë character from training data...generate_cards.py who loudly removes that card from the processing and finishes the rest of the cardsrender.py
encode.pytorch-rnn to handle rand_mtg_fields argument given new field sep, card sep, and mana formats from encode.py ?
scripts/generate_cards.py is the main entry point. This will
4 separate AIs contribute to the card design, so that certain attributes can be lifted out of scope from the main text training data.
nns/names* is an LSTM created for this project and trained to generate card names. This was trained both on all exisitng MTG card names as well as on a smattering of other words, phrases, and name-like strings. This increases the diversity of names outside of normal MTG card names.nns/main_text* is an LSTM created for this project and trained to generate all functional attributes and text of the cards. This was trained on select fields from all MTG cards (at time of training). This AI is whispered the names generated by the above AI during sampling.llm.A1SD.generate_cards.py, which pulls all the ingredients together to create new cards.scripts/generate_cards.py
python generate_cards.py --lstm_gpu 1 --names_nn ../nns/names_3 --main_text_nn ../nns/main_text_13 --flavor_nn timdettmers_guanaco-65b-merged --gpu-memory 23 --cpu-memory 250 --sd_nn "nov_mtg_art_v2_3.ckpt [76fcbf0ef5]" --outdir ../outputs --num_cards 10 --hr_upscale 2 --verbosity=9 --to_pdf
python generate_cards.py --help for more info on arguments*_cache) under the auto-generated output folder (eg ../outputs/00003_481992436), so the generator can be stopped and resumed without losing much via the --resume_folder ... argument. Also useful if it crashes for some inconsistent reason.stats.yaml in the output foldercard_data.yaml in the output folderprintable_cards.pdf) if you specify the --to_pdf arg| args | timing on the dev's machine | amount of data produced |
|---|---|---|
--hr_upscale 2 (all features enabled) | ~ 5-10 minutes per card | ~ 5 MB / card |
--no_flavor --hr_upscale 2 | ~ 2.5 cards / minute | ~ 4.5 MB / card |
--no_flavor | ~ 6.5 cards / minute | ~ 2.5 MB / card |
--no_flavor --no_art | ~ 10 cards / minute | ~ 250 KB / card |
--no_flavor --no_art --no_render | ~ 20 cards / minute | ~ 1.5 KB / card |
--to_pdf (ignoring other args + steps) | Adds ~ 20-40s per card, somehow this scales quadratically | roughly +50% |
python generate_cards.py --sd_nn "nov_mtg_art_v2_3.ckpt [76fcbf0ef5]" --verbosity=9 --outdir ../outputs --hr_upscale 2 --basic_lands "{'Plains':51, 'Island':51, 'Swamp':51, 'Mountain':51, 'Forest':51, 'Snow-Covered Plains':25, 'Snow-Covered Island':25, 'Snow-Covered Swamp':25, 'Snow-Covered Mountain':25, 'Snow-Covered Forest':25, 'Wastes':36}" --to_pdfgenerate_cards.py like normal plus args --no_flavor --no_art --no_render, so that only the text is generatedcard_data.yaml, and hand-modify the contents to your heart's desire. You can also delete cards entirely from the file.generate_cards.py like normal with --finish_yaml <yaml path>--resume_folder <folder path> (and specify the same args)Install NVidia CUDA toolkit version 11.8. (Trying newer versions may require manual customization of subtrees, especially torch-rnn which is no longer developed.)
A1SD/models/ldm/stable-diffusion-v1/. Git does not support large files (several GB), so these files are not committed to the repo.install_dir in webui.shCOMMANDLINE_ARGS in webui-user.sh based on your amount of ram, see docsbash webui.sh to finish setup
Running on local URL: http://127.0.0.1:7860)ctrl+c it to close the process for nowcd llmbash setup.sh
conda run -n llm python download-model.py timdettmers/guanaco-65b-merged (~160 GB)
server.py to finish setup
Running on local URL: )ctrl+c it to close the process for now~/torch and fiddle until it works. The order of these steps is critical. If you screw up, its often easier to rm -rf ~/torch and start over than try to recover.libhdf5-dev
deb [trusted=yes check-valid-until=no] http://dk.archive.ubuntu.com/ubuntu/ trusty main universe to /etc/apt/sources.listsudo apt updatesudo apt-get install libhdf5-dev==1.8.11*sudo apt-mark hold libhdf5-dev to pin versionconda env create -f environment-python.yaml. Use this enviropnment only for the preprocessing scriptgcc-6 and g++-6, since the older torch repo + cuda combination only works with this version
deb [trusted=yes] http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to /etc/apt/sources.listsudo apt updatesudo apt install gcc-6 g++-6gcc-6 and g++-6
sudo ln -s /usr/bin/gcc-6 /usr/local/cuda/bin/gccsudo ln -s /usr/bin/g++-6 /usr/local/cuda/bin/g++sudo ln -s -T /usr/local/cuda-11.8/lib64/libcublas.so /usr/lib/x86_64-linux-gnu/libcublas_device.sosudo add-apt-repository ppa:ubuntuhandbook1/ppa and sudo apt-get updategit config --global url."https://github.com/".insteadOf [email protected]git config --global url."https://".insteadOf git://pip install ipythonsudo apt-get purge cmakecd ~git clone https://github.com/Kitware/CMake.gitcd CMake./bootstrap; make; sudo make installbash install_torch.sh |& tee log-torch-install.txt. There will be several prompts.
sudo apt install expect to get unbuffer commandconda env create -f environment.yamlnltk language files
cd ~/nltk_datapython -c "import nltk; nltk.download('punkt')"AllPrintings.json from mtgjson website to raw_data_sources/.raw_data_sources/names.yaml and raw_data_sources/flavor.yaml manually with additional training databash rebuild_data_sources.sh |& tee log-data-build.txt in scripts/
Average chunk length for each AI to update constants in generate_cards.py -> LSTM_LEN_PER_MAIN_TEXT, LSTM_LEN_PER_NAME, and LSTM_LEN_PER_FLAVORLongest chunk length for each AI to set minimum -seq_length argument to train.luaTotal vocabulary size for each AI to set -wordvec_size argument to train.lua?scripts/encode.pyth train.lua -gpu 0 -input_h5 ../encoded_data_sources/names.h5 -input_json ../encoded_data_sources/names.json -checkpoint_name ../nns/names_3/checkpoint -rand_chunks_n_epochs 5 -checkpoint_n_epochs 100 -validate_n_epochs 10 -print_every 1 -num_layers 3 -rnn_sizes "200, 200, 200" -max_epochs 100000000 -batch_size 2000 -seq_length 150 -dropout 0.5 -learning_rate 0.02 -lr_decay_n_epochs 30 -lr_decay_factor 0.985 -wordvec_size 74th train.lua -gpu 0 -input_h5 ../encoded_data_sources/main_text.h5 -input_json ../encoded_data_sources/main_text.json -checkpoint_name ../nns/main_text_13/checkpoint -rand_chunks_n_epochs 1 -checkpoint_n_epochs 30 -validate_n_epochs 1 -print_every 1 -num_layers 4 -rnn_sizes "600, 600, 600, 600" -max_epochs 100000000 -batch_size 260 -seq_length 900 -dropout 0.5 -learning_rate 0.001 -lr_decay_n_epochs 10 -lr_decay_factor 0.99 -wordvec_size 122th train.lua -input_h5 ../encoded_data_sources/flavor.h5 -input_json ../encoded_data_sources/flavor.json -checkpoint_name ../nns/flavor_0/checkpoint -rand_chunks_n_epochs 1 -checkpoint_n_epochs 100 -validate_n_epochs 1 -print_every 1 -num_layers 3 -rnn_size 256 -max_epochs 100000000 -batch_size 200 -seq_length 500 -dropout 0.5 -learning_rate 0.002 -lr_decay_n_epochs 50 -lr_decay_factor 0.99CTRL+c to stop training when the AI is ready. Use scripts/plot_nn_loss.py to assess progress.th sample.lua -checkpoint ../nns/names_0/checkpoint_1001.000000.t7 -length 50. The main generator will use a similar command to sample the AIs when generating cards.raw_data_sources include user inputs for AI training data. These are processed into encoded_data_sources via rebuild_data_sources.sh, which utilizes scripts/encode.py and torch-rnn.nns contains trained text-based neural networkstorch-rnn contains code for training and sampling the text neural networksA1SD contains image generating neural networks and associated code.llm contains text generating neural networks and associated code.scripts contains the main generator entry point generate_cards.py as well as intermediary and utility scriptsoutputs contains rendered card images, card sheets, full text and stats yaml files, and cached intermediate stepsimage_templates contains template images for rendering the generated cardssetup.pywatch -n1 nvidia-smi to see GPU resource utilizationfind . -name "*.svg" | xargs inkscape --export-type=png --export-width=1000 --export-height=1000 --export-png-color-mode=RGBA_8 --batch-processpython plot_nn_loss.py --json_path nns/names_1/checkpoint_21.000000.jsonenvironment.yaml update the environment with conda deactivate && conda env remove --name mtg-ai-main && conda env create -f environment.yaml && conda activate mtg-ai-maingit remote add -f <name> <url>git subtree add --prefix <dir> <remote> <branch> --squashgit fetch <remote> <branch> and then git subtree pull --prefix <dir> <remote> <branch> --squashlr_lockout_zone parameter, which is the width and height of a box protruding into the lower right corner of hte text area, overwhich text should not be rendered. Implement "not rendering text in that area" by checking currently rendered line height and prospective width against the new constraints every time a rendered-text image is considered for addition to the current line.main_text and names instead of LSTMscard_data.yaml
card_data.yaml when its defined at time of file writing, and omit when its notnns_names attribute from the yaml, and repalce it with individual network name attributes (eg nn_names)to_tts_asset.py to format cards into sheets for upload to TTS
names_3 after removal of ë character from training data...generate_cards.py who loudly removes that card from the processing and finishes the rest of the cardsrender.py
encode.pytorch-rnn to handle rand_mtg_fields argument given new field sep, card sep, and mana formats from encode.py ?