Guest User

Universal patch.ps1

a guest
Jul 21st, 2021
3,885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ПАЧЬ: https://pastebin.com/zu1yQ5C0
  2. # 1. Закинуть в папку с симсвопом
  3. # 2. Запустить
  4.  
  5. # Делает симсвоп ЦП-совместимым, а не просто эксклюзивным. Отдельную версию торча вроде как качать не нужно.
  6.  
  7. <# :
  8. @echo off
  9. powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
  10. exit /b
  11. : #>
  12. <# :
  13. @echo off
  14. powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
  15. exit /b
  16. : #>
  17. $search_replace = @{
  18.     "if len(self.opt.gpu_ids)" = "if torch.cuda.is_available() and len(self.opt.gpu_ids)";
  19.     "torch.device(`"cuda:0`")" = "torch.device(`'cuda:0`' if torch.cuda.is_available() else `'cpu`')";
  20.     "torch.load(netArc_checkpoint)" = "torch.load(netArc_checkpoint) if torch.cuda.is_available() else torch.load(netArc_checkpoint, map_location=torch.device(`'cpu`'))";
  21.     "net.load_state_dict(torch.load(save_pth))" = "net.load_state_dict(torch.load(save_pth)) if torch.cuda.is_available() else net.load_state_dict(torch.load(save_pth, map_location=torch.device(`'cpu`')))";
  22.     ".cuda()" = ".to(torch.device(`'cuda:0`' if torch.cuda.is_available() else `'cpu`'))";
  23.     ".to('cuda')" = ".to(torch.device(`'cuda:0`' if torch.cuda.is_available() else `'cpu`'))";
  24. }
  25.  
  26. ForEach ($File in (Get-ChildItem -Path '.\*.py' -Recurse -File)) {
  27.     $content = (Get-Content $File)
  28.     if ($content.length -gt 0) {
  29.         ForEach ($search in $search_replace.Keys) {
  30.             $content = $content.replace("$search", "$($search_replace[$search])")
  31.         }
  32.         Set-Content $File $content
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment