{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"#安装目录\ninstall_path='/kaggle/working'\n\n#内网传透\nuseNgrok = 1 # 非必填 是否使用ngrok作为公网访问地址\n#tesoerboard\nngrokTokenFile='/kaggle/input/ngroktoken/Authtoken.txt' # 非必填 存放ngrokToken的文件的路径\nport = 6006\n#炼丹炉的gui\nngrokTokenFile1='/kaggle/input/ngroktoken/Authtoken1.txt' # 非必填 存放ngrokToken的文件的路径\nport1 = 28000\n\n#优化\nmulti_gpu = 0 \nlowram = 0\n\n#删除脚本重新安装\nreLoad = 0\n\n#更新脚本\nupdata = 1\n\n#自动打包训练好的模型\nzip_output = 1\n#自动清理\nclear_output = 1\n#自动上传抱脸\nupload = 1\nhugTokenFile='/kaggle/input/hugfacetoken/hugfacetoken.txt' # 非必填 存放hugfacetoken的文件的路径\n#仓库名\nrepo_id=\"sukaka/train_model\"\n#上传仓库路径\npath_in_repo=\"模型.zip\"","metadata":{"execution":{"iopub.status.busy":"2023-05-13T06:39:11.288339Z","iopub.execute_input":"2023-05-13T06:39:11.289426Z","iopub.status.idle":"2023-05-13T06:39:11.299752Z","shell.execute_reply.started":"2023-05-13T06:39:11.289379Z","shell.execute_reply":"2023-05-13T06:39:11.298045Z"},"trusted":true},"execution_count":45,"outputs":[]},{"cell_type":"code","source":"#开启图形化配置参数\nuse_gui = 1\n\n#一键倒入炼丹参数\nconfig_file='#/kaggle/input/input-qin/qin.toml'\n\n#炼丹参数配置,如果使用gui或一键导入炼丹参数,请忽略以下\npretrained_model = \"/kaggle/input/9527-fp16/9527.safetensors\"\nis_v2_model = 0\nparameterization = 0\ntrain_data_dir = \"/kaggle/input/input-qin/input_qin\"\nreg_data_dir = \"\"\nnetwork_module = \"networks.lora\"\nnetwork_weights = \"\"\nnetwork_dim = 32\nnetwork_alpha = 32\nresolution = \"512,768\"\nbatch_size = 1\nmax_train_epoches = 10\nsave_every_n_epochs = 2\ntrain_unet_only = 0\ntrain_text_encoder_only = 0\nstop_text_encoder_training = 0\nnoise_offset = \"0\"\nkeep_tokens = 0\nmin_snr_gamma = 0\nlr = \"1e-4\"\nunet_lr = \"1e-4\"\ntext_encoder_lr = \"1e-5\"\nlr_scheduler = \"cosine_with_restarts\"\nlr_warmup_steps = 0\nlr_restart_cycles = 1\noutput_name = \"qin\"\nsave_model_as = \"safetensors\"\nsave_state = 0\nresume = \"\"\nmin_bucket_reso = 256\nmax_bucket_reso = 1024\npersistent_data_loader_workers = 0\nclip_skip = 2\n\n# Optimizer settings\noptimizer_type = \"AdamW8bit\" # Optimizer type | Available options: AdamW AdamW8bit Lion SGDNesterov SGDNesterov8bit DAdaptation AdaFactor\n\n# LyCORIS training settings\nalgo = \"lora\" # LyCORIS network algo | Available options: lora, loha, lokr, ia3, dylora. lora is equivalent to locon\nconv_dim = 4 # conv dim | Similar to network_dim, recommended to be 4\nconv_alpha = 4 # conv alpha | Similar to network_alpha, can use same or smaller values than conv_dim\ndropout = \"0\" # dropout | Dropout probability, 0 means no dropout, larger values mean more dropout. LoHa/LoKr/(IA)^3 do not currently support dropout","metadata":{"execution":{"iopub.status.busy":"2023-05-13T06:39:11.335684Z","iopub.execute_input":"2023-05-13T06:39:11.336353Z","iopub.status.idle":"2023-05-13T06:39:11.350331Z","shell.execute_reply.started":"2023-05-13T06:39:11.336307Z","shell.execute_reply":"2023-05-13T06:39:11.348823Z"},"trusted":true},"execution_count":47,"outputs":[]},{"cell_type":"code","source":"import shutil\nimport gc\nimport os\nimport time\nimport subprocess\nimport multiprocessing\nimport inspect\nimport pkg_resources\nfrom pathlib import Path\nfrom concurrent.futures import ProcessPoolExecutor\nos.environ['install_path'] = install_path\nos.environ['HF_HOME'] = 'huggingface'\nos.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\nos.environ[\"PL_TORCH_DISTRIBUTED_BACKEND\"] = \"gloo\"\n \ndef libtcmalloc():\n if \"LD_PRELOAD\" in os.environ and os.environ[\"LD_PRELOAD\"] == \"libtcmalloc.so\":\n return\n os.chdir('/kaggle')\n os.mkdir('temp')\n os.chdir('temp')\n os.system('wget -qq http://launchpadlibrarian.net/367274644/libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb')\n os.system('wget -qq https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/google-perftools_2.5-2.2ubuntu3_all.deb')\n os.system('wget -qq https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb')\n os.system('wget -qq https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb')\n os.system('apt install -qq libunwind8-dev -y')\n os.system('dpkg -i *.deb')\n os.system('rm *.deb')\n os.environ[\"LD_PRELOAD\"] = \"libtcmalloc.so\"\n \ndef LoRA_scripts_install():\n %cd $install_path\n if reLoad == 1:\n !rm -rf lora-scripts\n if Path(\"lora-scripts\").exists():\n if updata == 1:\n %cd lora-scripts\n !git checkout .\n !git pull\n print('LoRA-scripts已更新')\n else:\n print('LoRA-scripts已安装')\n else:\n print('LoRA-scripts安装中')\n #下载秋叶的脚本\n !git clone --recurse-submodules https://github.com/Akegarasu/lora-scripts\n print('LoRA-scripts已安装')\n\ndef venv_install():\n %cd /opt/conda/envs\n if os.path.exists('venv'):\n print('环境已安装')\n else:\n %cd /kaggle/working/\n if not os.path.exists('venv.tar.gz'):\n print('环境包下载中')\n !wget https://huggingface.co./datasets/sukaka/venv_ai_drow/resolve/main/lora_train_py31010_torch2_cu118_xf17.tar.gz -O venv.tar.gz\n print('环境包已下载')\n %cd /opt/conda/envs/\n !mkdir venv\n %cd venv\n print('环境安装中')\n !tar -xzf /kaggle/working/venv.tar.gz\n !source /opt/conda/bin/activate venv\n print('环境安装完毕')\n \ndef pip():\n installed_packages = [pkg.key for pkg in pkg_resources.working_set]\n if 'huggingface_hub' not in installed_packages or 'pyngrok' not in installed_packages:\n os.system('pip install -q huggingface_hub pyngrok')","metadata":{"execution":{"iopub.status.busy":"2023-05-13T06:39:11.353465Z","iopub.execute_input":"2023-05-13T06:39:11.354300Z","iopub.status.idle":"2023-05-13T06:39:11.542567Z","shell.execute_reply.started":"2023-05-13T06:39:11.354252Z","shell.execute_reply":"2023-05-13T06:39:11.541487Z"},"trusted":true},"execution_count":48,"outputs":[]},{"cell_type":"code","source":"def ngrok_start(ngrokTokenFile: str, port: int, address_name: str):\n if Path(ngrokTokenFile).exists():\n with open(ngrokTokenFile, encoding=\"utf-8\") as nkfile:\n ngrokToken = nkfile.readline()\n print('use nrgok')\n from pyngrok import conf, ngrok\n conf.get_default().auth_token = ngrokToken\n conf.get_default().monitor_thread = False\n ssh_tunnels = ngrok.get_tunnels(conf.get_default())\n if len(ssh_tunnels) == 0:\n ssh_tunnel = ngrok.connect(port, bind_tls=True)\n print(f'{address_name}:' + ssh_tunnel.public_url)\n else:\n print(f'{address_name}:' + ssh_tunnels[0].public_url)\n else:\n print('skip start ngrok')","metadata":{"execution":{"iopub.status.busy":"2023-05-13T06:39:11.546574Z","iopub.execute_input":"2023-05-13T06:39:11.547227Z","iopub.status.idle":"2023-05-13T06:39:11.558958Z","shell.execute_reply.started":"2023-05-13T06:39:11.547191Z","shell.execute_reply":"2023-05-13T06:39:11.557754Z"},"trusted":true},"execution_count":49,"outputs":[]},{"cell_type":"code","source":"def tensorboard_start():\n ngrok_start(ngrokTokenFile,port,'tensorboard地址')\n %cd $install_path/lora-scripts\n !conda run -n venv --no-capture-output tensorboard --logdir='logs'\n\ndef gui(launch_args,port: int):\n import argparse\n import json\n import webbrowser\n from datetime import datetime\n from threading import Lock\n import uvicorn\n from fastapi import BackgroundTasks, FastAPI, Request\n from fastapi.responses import FileResponse\n from fastapi.staticfiles import StaticFiles\n import toml\n\n app = FastAPI()\n\n lock = Lock()\n\n # fix mimetype error in some fucking systems\n sf = StaticFiles(directory=\"frontend/dist\")\n _o_fr = sf.file_response\n def _hooked_file_response(*args, **kwargs):\n full_path = args[0]\n r = _o_fr(*args, **kwargs)\n if full_path.endswith(\".js\"):\n r.media_type = \"application/javascript\"\n elif full_path.endswith(\".css\"):\n r.media_type = \"text/css\"\n return r\n sf.file_response = _hooked_file_response\n\n parser = argparse.ArgumentParser(description=\"GUI for training network\")\n parser.add_argument(\"--port\", type=int, default=port, help=\"Port to run the server on\")\n\n def run_train(toml_path: str):\n print(f\"Training started with config file / 训练开始,使用配置文件: {toml_path}\")\n cmd = f\"conda run -n venv --no-capture-output accelerate launch {' '.join(launch_args)} sd-scripts/train_network.py --config_file {toml_path}\"\n try:\n result = subprocess.run(cmd, shell=True, env=os.environ)\n if result.returncode != 0:\n print(f\"Training failed / 训练失败\")\n else:\n print(f\"Training finished / 训练完成\")\n except Exception as e:\n print(f\"An error occurred when training / 创建训练进程时出现致命错误: {e}\")\n finally:\n lock.release()\n\n\n @app.post(\"/api/run\")\n async def create_toml_file(request: Request, background_tasks: BackgroundTasks):\n acquired = lock.acquire(blocking=False)\n\n if not acquired:\n print(\"Training is already running / 已有正在进行的训练\")\n return {\"status\": \"fail\", \"detail\": \"Training is already running\"}\n\n timestamp = datetime.now().strftime(\"%Y%m%d-%H%M%S\")\n toml_file = f\"toml/{timestamp}.toml\"\n toml_data = await request.body()\n j = json.loads(toml_data.decode(\"utf-8\"))\n with open(toml_file, \"w\") as f:\n f.write(toml.dumps(j))\n background_tasks.add_task(run_train, toml_file)\n return {\"status\": \"success\"}\n\n @app.middleware(\"http\")\n async def add_cache_control_header(request, call_next):\n response = await call_next(request)\n response.headers[\"Cache-Control\"] = \"max-age=0\"\n return response\n\n @app.get(\"/\")\n async def index():\n return FileResponse(\"./frontend/dist/index.html\")\n\n app.mount(\"/\", sf, name=\"static\")\n\n if __name__ == \"__main__\":\n args, _ = parser.parse_known_args()\n print(f\"Server started at http://127.0.0.1:{port}\")\n\n webbrowser.open(f\"http://127.0.0.1:{port}\")\n uvicorn.run(app, host=\"127.0.0.1\", port=port, log_level=\"error\")\n\ndef train_start():\n %cd /kaggle/working\n !mkdir output\n %cd $install_path/lora-scripts\n\n ext_args = []\n launch_args = []\n if multi_gpu == 1:\n launch_args.append('--multi_gpu')\n launch_args.append('--num_processes=2')\n if use_gui == 1:\n ngrok_start(ngrokTokenFile1,port1,'炼丹炉gui')\n gui(launch_args,port1)\n else:\n if Path(config_file).is_file():\n cmd = f\"\"\"conda run -n venv --no-capture-output accelerate launch {' '.join(launch_args)} \"sd-scripts/train_network.py\" \\\n --config_file={config_file}\"\"\"\n os.system(cmd)\n else:\n if lowram == 1:\n ext_args.append('--lowram')\n\n if is_v2_model == 1:\n ext_args.append('--v2')\n else:\n ext_args.append(f'--clip_skip {clip_skip}')\n\n if parameterization == 1:\n ext_args.append('--v_parameterization')\n\n if train_unet_only == 1:\n ext_args.append('--network_train_unet_only')\n\n if train_text_encoder_only == 1:\n ext_args.append('--network_train_text_encoder_only')\n\n if network_weights:\n ext_args.append(f'--network_weights {network_weights}')\n\n if reg_data_dir:\n ext_args.append(f'--reg_data_dir {reg_data_dir}')\n\n if optimizer_type:\n ext_args.append(f'--optimizer_type {optimizer_type}')\n\n if optimizer_type == 'DAdaptation':\n ext_args.append('--optimizer_args decouple=True')\n\n if save_state == 1:\n ext_args.append('--save_state')\n\n if resume:\n ext_args.append(f'--resume {resume}')\n\n if persistent_data_loader_workers == 1:\n ext_args.append('--persistent_data_loader_workers')\n\n if network_module == 'lycoris.kohya':\n ext_args.append(f'--network_args conv_dim={conv_dim} conv_alpha={conv_alpha} algo={algo} dropout={dropout}')\n\n if stop_text_encoder_training != 0:\n ext_args.append(f'--stop_text_encoder_training {stop_text_encoder_training}')\n\n if noise_offset != '0':\n ext_args.append(f'--noise_offset {noise_offset}')\n\n if min_snr_gamma != 0:\n ext_args.append(f'--min_snr_gamma {min_snr_gamma}')\n\n cmd = f\"\"\"conda run -n venv --no-capture-output accelerate launch {' '.join(launch_args)} \"sd-scripts/train_network.py\" \\\n --enable_bucket \\\n --pretrained_model_name_or_path={pretrained_model} \\\n --train_data_dir={train_data_dir} \\\n --output_dir=\"/kaggle/working/output\" \\\n --logging_dir=\"logs\" \\\n --log_prefix={output_name} \\\n --resolution={resolution} \\\n --network_module={network_module} \\\n --max_train_epochs={max_train_epoches} \\\n --learning_rate={lr} \\\n --unet_lr={unet_lr} \\\n --text_encoder_lr={text_encoder_lr} \\\n --lr_scheduler={lr_scheduler} \\\n --lr_warmup_steps={lr_warmup_steps} \\\n --lr_scheduler_num_cycles={lr_restart_cycles} \\\n --network_dim={network_dim} \\\n --network_alpha={network_alpha} \\\n --output_name={output_name} \\\n --train_batch_size={batch_size} \\\n --save_every_n_epochs={save_every_n_epochs} \\\n --mixed_precision=\"fp16\" \\\n --save_precision=\"fp16\" \\\n --seed=\"1337\" \\\n --cache_latents \\\n --prior_loss_weight=1 \\\n --max_token_length=225 \\\n --caption_extension=\".txt\" \\\n --save_model_as={save_model_as} \\\n --min_bucket_reso={min_bucket_reso} \\\n --max_bucket_reso={max_bucket_reso} \\\n --keep_tokens={keep_tokens} \\\n --xformers --shuffle_caption {' '.join(ext_args)} \"\"\"\n os.system(cmd)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-13T06:39:11.562344Z","iopub.execute_input":"2023-05-13T06:39:11.562778Z","iopub.status.idle":"2023-05-13T06:39:11.688313Z","shell.execute_reply.started":"2023-05-13T06:39:11.562689Z","shell.execute_reply":"2023-05-13T06:39:11.687064Z"},"trusted":true},"execution_count":50,"outputs":[]},{"cell_type":"code","source":"main():\n startTicks = time.time()\n with ProcessPoolExecutor() as executor:\n futures = [executor.submit(func) for func in [libtcmalloc, pip, LoRA_scripts_install, venv_install]]\n for future in futures:\n future.result()\n startTicks = time.time()\n with ProcessPoolExecutor() as executor:\n futures = [executor.submit(func) for func in [tensorboard_start, train_start]]\n for future in futures:\n future.result()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def hugface_upload():\n if Path(hugTokenFile).exists():\n with open(hugTokenFile,encoding = \"utf-8\") as nkfile:\n hugToken = nkfile.readline()\n if upload == 1 and hugToken != '':\n from huggingface_hub import login\n # 使用您的 Hugging Face 访问令牌登录\n login(token= hugToken)\n from huggingface_hub import HfApi\n # 实例化 HfApi 类\n api = HfApi()\n print(\"HfApi 类已实例化\")\n\n # 使用 upload_file() 函数上传文件\n print(\"开始上传文件...\")\n response = api.upload_file(\n path_or_fileobj=\"/kaggle/working/模型.zip\",\n path_in_repo={path_in_repo},\n repo_id={repo_id},\n repo_type=\"dataset\"\n )\n print(\"文件上传完成\")\n print(f\"响应: {response}\")\n\ndef zip_clear():\n if zip_output == 1:\n shutil.make_archive('/kaggle/working/模型', 'zip', '/kaggle/working/output/')\n print('模型已压缩到output')\n if clear_output == 1:\n def clear_directory(folder_path):\n for filename in os.listdir(folder_path):\n file_path = os.path.join(folder_path, filename)\n if os.path.isfile(file_path) or os.path.islink(file_path):\n os.unlink(file_path)\n elif os.path.isdir(file_path):\n shutil.rmtree(file_path)\n clear_directory('/kaggle/working/output')\n clear_directory('/kaggle/working/lora-scripts/logs')\n print('清理完毕')\n\ndef after_train():\n zip_clear()\n hugface_upload()\n","metadata":{"execution":{"iopub.status.busy":"2023-05-13T06:39:11.692391Z","iopub.execute_input":"2023-05-13T06:39:11.692736Z","iopub.status.idle":"2023-05-13T06:39:11.706948Z","shell.execute_reply.started":"2023-05-13T06:39:11.692706Z","shell.execute_reply":"2023-05-13T06:39:11.705665Z"},"trusted":true},"execution_count":51,"outputs":[]},{"cell_type":"code","source":"main()","metadata":{"execution":{"iopub.status.busy":"2023-05-13T06:39:11.708314Z","iopub.execute_input":"2023-05-13T06:39:11.709406Z","iopub.status.idle":"2023-05-13T06:41:30.754064Z","shell.execute_reply.started":"2023-05-13T06:39:11.709362Z","shell.execute_reply":"2023-05-13T06:41:30.752185Z"},"trusted":true},"execution_count":52,"outputs":[{"name":"stdout","text":"/kaggle/working\n/opt/conda/envs\n环境已安装\n/opt/conda/envs/lora-scripts\nUpdated 0 paths from the index\nAlready up to date.\nLoRA-scripts已更新\n","output_type":"stream"},{"name":"stderr","text":"WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\n","output_type":"stream"},{"name":"stdout","text":"加载耗时: 13.430296897888184 s\nuse nrgok/kaggle/working\n\ntensorboard地址:https://3594-34-27-227-19.ngrok-free.app\n/kaggle/working/lora-scripts\nmkdir: cannot create directory ‘output’: File exists\n/kaggle/working/lora-scripts\nuse nrgok\n炼丹炉gui:https://b292-34-27-227-19.ngrok-free.app\nServer started at http://127.0.0.1:28000\n\nNOTE: Using experimental fast data loading logic. To disable, pass\n \"--load_fast=false\" and report issues on GitHub. More details:\n https://github.com/tensorflow/tensorboard/issues/4784\n\nServing TensorBoard on localhost; to expose to the network, use a proxy or pass --bind_all\nTensorBoard 2.10.1 at http://localhost:6006/ (Press CTRL+C to quit)\n","output_type":"stream"},{"traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)","\u001b[0;32m/tmp/ipykernel_23/451043146.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m/tmp/ipykernel_23/4105154296.py\u001b[0m in \u001b[0;36mmain\u001b[0;34m()\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0mp1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstart\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0mp2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstart\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0mp1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 16\u001b[0m \u001b[0mp2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/opt/conda/lib/python3.7/multiprocessing/process.py\u001b[0m in \u001b[0;36mjoin\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 138\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_parent_pid\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetpid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'can only join a child process'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 139\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_popen\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'can only join a started process'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 140\u001b[0;31m \u001b[0mres\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_popen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 141\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mres\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 142\u001b[0m \u001b[0m_children\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdiscard\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/opt/conda/lib/python3.7/multiprocessing/popen_fork.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[0;31m# This shouldn't block if wait() returned successfully.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 48\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpoll\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mWNOHANG\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0.0\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 49\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/opt/conda/lib/python3.7/multiprocessing/popen_fork.py\u001b[0m in \u001b[0;36mpoll\u001b[0;34m(self, flag)\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 28\u001b[0;31m \u001b[0mpid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwaitpid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mflag\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 29\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mOSError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 30\u001b[0m \u001b[0;31m# Child process not yet created. See #1731717\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mKeyboardInterrupt\u001b[0m: "],"ename":"KeyboardInterrupt","evalue":"","output_type":"error"},{"name":"stdout","text":"^C\n","output_type":"stream"}]},{"cell_type":"code","source":"#训练完毕,手动执行。进行打包和上传\nafter_train()","metadata":{"execution":{"iopub.status.busy":"2023-05-13T06:41:30.757994Z","iopub.status.idle":"2023-05-13T06:41:30.759093Z","shell.execute_reply.started":"2023-05-13T06:41:30.758721Z","shell.execute_reply":"2023-05-13T06:41:30.758753Z"},"trusted":true},"execution_count":null,"outputs":[]}]}