一 stable diffusion简介
stable diffusion和mid journey是现今最为流行的2个A训练工具
stable diffusion开源,插件和配置项较多
mid journey非开源,操作较为简单

二 github下载源码
https://github.com/AUTOMATIC1111/stable-diffusion-webui

三 根据当前版本的readme文件进行安装
Installation and Running推荐的安装步骤为:
1 确认及更新显卡驱动
2 安装Python
3 安装git
4 下载仓库
5 运行批处理

四 安装Python
建议的版本为3.10.6
安装时勾选Add Python to PATH
安装后确认版本:python -V
版本异常检查环境变量

五 更新显卡驱动
命令行执行
nvidia-smi
确认当前为CUDA Version: 11.7

在developer.download.nvidia.cn下载对应斑斑
https://developer.download.nvidia.cn/compute/cuda/11.7.0/local_installers/cuda_11.7.0_516.01_windows.exe

在命令行确认当前版本
nvcc -V

六 运行批处理
文件夹下直接点击webui-user.bat

七 从入门到放弃
卡顿 无法安装
使用B站秋葉aaaki的整合包
https://www.bilibili.com/video/BV1iM4y1y7oA

八 问题解决
提示:No module 'xformers'. Proceeding without it
webui-user.bat”文件,添加--xformers参数
set COMMANDLINE_ARGS=--xformers

提示RuntimeError: No CUDA GPUs are available
命令行
python
import torch
torch.cuda.device_count()
torch.cuda.is_available()
发现为false

print(torch.__version__)
发现为2.0.0+cpu
cpu版本而非GPU版本

安装GPU版本Pytorch
根据官网选项生成在线安装命令
https://pytorch.org/get-started/locally/
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117

执行报错
Requirement already satisfied: torch in XXX
进入所在目录
针对提示删除torch开头的文件夹
重新执行安装命令

1 获取数据盘的设备名称
fdisk -lu
/dev/vdb1是新增数据盘

2 安装Parted工具
yum install -y parted

3 开始分区
parted /dev/vdb1
设置GPT分区格式
mklabel gpt
划分一个主分区、分区名为primary且100%容量给到第一个分区
mkpart primary 1 100%
检查分区是否对齐
align-check optimal 1
如果分区是对齐的,结果如下
1 aligned
查看分区表
print
退出Parted工具
quit

4 使系统重读分区表
partprobe

5 查看新分区信息
fdisk -lu /dev/vdb1

6 配置/etc/fstab文件并挂载分区
备份/etc/fstab文件
cp /etc/fstab /etc/fstab.bak

7 在/etc/fstab里写入新分区信息
echo blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"//g' /mnt ext4 defaults 0 0 >> /etc/fstab

8 查看/etc/fstab中的新分区信息
cat /etc/fstab

9 挂载/etc/fstab配置的文件系统

1 全局安装electron
npm install electron -g

2 全局安装electron-packager
npm install electron-packager -g

3 更改uniapp的manifest.json修改
运行的基础路径修改为:./
去掉启用https协议

4 新建打包目录
static
package.json
main.js
index.html

其中package.json的内容为:

{
"name" : "app-name",
"version" : "0.1.0",
"main" : "main.js"
}

main.js的内容为

const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win

function createWindow () {
  // Create the browser window.
  win = new BrowserWindow({width: 800, height: 600})

  // and load the index.html of the app.
  win.loadURL(url.format({
    pathname: path.join(__dirname, 'index.html'),
    protocol: 'file:',
    slashes: true
  }))

  // Open the DevTools.
  // win.webContents.openDevTools()

  // Emitted when the window is closed.
  win.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    win = null
  })
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // On macOS it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  // On macOS it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (win === null) {
    createWindow()
  }
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

5 进入目录,确认electron版本
electron-v

6 打包
electron-packager . MyApp --win --out MyApp --arch=x64 --electron-version 24.1.2 --overwrite --ignore=node_modules

7 加密源文件
cd MyAppMyApp-win32-x64resources

8 全局安装asar
npm install asar -g

9 加密
asar pack ./app app.asar

10 隐藏菜单
main.js的第一行改为

const { app, BrowserWindow, Menu } = require("electron");
// 禁用菜单,一般情况下,不需要禁用
Menu.setApplicationMenu(null);