【ComfyUI】MacBook Pro 安装(Intel 集成显卡)

环境

显卡:Intel Iris Plus Graphics 1536 MB
macos: 13.0 (22A380)

概述

看之前,一定要确认环境。
看之前,一定要确认环境。
看之前,一定要确认环境。

我这台MacBook Pro是英特尔的集成显卡,所以用不了CUDA,也就用不了GPU。
(主要是因为英特尔没有出相应的工具包)

所以按照ComfyUI思路就是,最终是要使用CPU来跑的。

配置pip镜像

# 设置清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn

配置pip代理

# 执行如下命令,没有会自动创建文件
vim ~/.pip/pip.conf
# 内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
# 这个地方根据自己的代理来配置,下面是我的代理软件的配置
# 因为我们配置的是清华的源,其他没有必要开代理
proxy = http://127.0.0.1:1087

[install]
trusted-host = pypi.tuna.tsinghua.edu.cn

这里记录下,Mac电脑查看配置文件读取顺序:

# 查看配置文件读取顺序
MacBook-Pro:openai yutao$ pip config list -v
For variant 'global', will try loading '/Library/Application Support/pip/pip.conf'
For variant 'user', will try loading '/Users/yutao/.pip/pip.conf'
For variant 'user', will try loading '/Users/yutao/.config/pip/pip.conf'
For variant 'site', will try loading '/Users/yutao/.pyenv/versions/3.10.9/pip.conf'

git配置(选配)

因为我在git clone代码时候,总是会报仓库找不到,所以我会配置:

git config --global url."git@github.com:".insteadOf "https://github.com/"

也就是通过配置,将https://github.com/替换为git@github.com:。

假设我们想删除的话,

git config --unset key名称
# 例如
git config --unset url.git@github.com:.insteadof

下载comfyUI代码

# 我使用git@xxx 总是报找不到仓库,所以就使用https的地址啦
git clone https://github.com/comfyanonymous/ComfyUI.git

创建、激活虚拟环境

虚拟环境:针对每个项目创建一个只属于自己的一套环境;
这个环境主要目的防止依赖版本冲突。
不要觉得是浪费空间,比起解决版本冲突所花费的时间,这点空间是值得的。

由于comfyUI不像stable diffusion webUI那样会帮我们自动创建虚拟环境。
所以我们需要手动创建虚拟环境。

# 在comfyui根目录下,创建名为:venv的虚拟环境:python -m venv venv
[MacBook-Pro:ComfyUI yutao$ python -m venv venv

# 激活虚拟环境:. source venv/bin/active
[MacBook-Pro:ComfyUI yutao$ . source venv/bin/active

# 退出虚拟环境:deactivate
(venv) MacBook-Pro:ComfyUI yutao$ deactivate

下载依赖

在激活虚拟环境的情况下,下载依赖:

[(venv) MacBook-Pro:ComfyUI yutao$ pip install -r requirements.txt

这一步,只要网络好的情况下,是不会报错的。

安装torchvision

翻查源码发现,ComfyUI/comfy_extras/chainner_models/model_loading.py文件会加载LaMa,而LaMa.py又会去加载torchvision。所以我们需要安装它,虽然它在requirements.txt文件中并没有出现。

# 先看看有没有安装,确定确实没有安装
[(venv) MacBook-Pro:ComfyUI yutao$ pip show torchvision
WARNING: Package(s) not found: torchvision

# 安装
[(venv) MacBook-Pro:ComfyUI yutao$ pip install torchvision

启动comfyUI

这里需要特别注意,因为MacBook Pro是英特尔的集成显卡,不支持CUDA,所以也就不支持GPU的使用。

启动时,一定要指明关闭GPU,使用CPU。

# 参数:--disable-cuda-malloc --use-split-cross-attention --cpu
(venv) MacBook-Pro:ComfyUI yutao$ python main.py --disable-cuda-malloc --use-split-cross-attention --cpu

# source /opt/intel/oneapi/setvars.sh && python main.py --use-split-cross-attention

参数说明:

  1. --cpu: 就是指明使用CPU来画图(就是时间上会很慢)
  2. --disable-cuda-malloc: 指明不使用CUDA。
  3. --use-split-cross-attention : 低内存的时候使用

运行成功后的界面:

Total VRAM 16384 MB, total RAM 16384 MB
Set vram state to: DISABLED
Device: cpu
VAE dtype: torch.float32
Using split optimization for cross attention
Starting server

To see the GUI go to: http://127.0.0.1:8188

在这里插入图片描述

目前还没有大模型,需要下载。

https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/tree/main
下载:sd_xl_base_1.0.safetensors文件,然后放入到ComfyUI/models/checkpoints目录下即可。

为什么Mac不支持CUDA,即英伟达的显卡?

老外给出的解释:

总结并扩展评论:
CUDA 是 Nvidia 专有(显然未经许可)的技术,允许在 GPU 处理器上进行通用计算。
很少有 Macbook Pro 配备支持 Nvidia CUDA 的 GPU。请查看此处,了解您的 MBP 是否具有 Nvidia GPU。然后,查看此处的表,看看该 GPU 是否支持 CUDA
iMac、iMac Pro 和 Mac Pro 的情况相同。
因此,在 MacOS 上默认安装 PyTorch 时不支持 CUDA
很少有 Mac 拥有 Nvidia 处理器:

安装Intel工具包

Intel® Distribution for Python

这是我最开始依然能行的思路,后来发现Intel目前就没有集成显卡的工具包。


参考地址:

How_to_install_ComfyUI

Intel Arc Graphics Thread

AssertionError: Torch not compiled with CUDA enabled

https://kwaa.dev/stable-diffusion

python设置代理和添加镜像源介绍

### 回答1: import xgboost as xgb from sklearn.grid_search import GridSearchCV# 设置参数列表 param_grid = { 'max_depth': [3, 4, 5], 'learning_rate': [0.01, 0.1, 0.2], 'n_estimators': [200, 400, 600], 'subsample': [0.8, 1.0], 'colsample_bytree': [0.8, 1.0] } # 使用GridSearchCV进行搜索 xgb_model = xgb.XGBClassifier() grid_search = GridSearchCV(xgb_model, param_grid, verbose=1, cv=5) grid_search.fit(X_train, y_train) # 输出最优参数 best_parameters = grid_search.best_params_ print(best_parameters) ### 回答2: XGBoost是一种常用的梯度提升树算法,可以用于分类和回归问题。调参是优化模型性能的关键步骤。下面是一个关于XGBoost机器学习模型调参的Python代码示例: ```python import xgboost as xgb from sklearn.datasets import load_boston from sklearn.model_selection import GridSearchCV, train_test_split from sklearn.metrics import mean_squared_error # 载入数据集 data = load_boston() X, y = data.data, data.target # 划分训练集和验证集 X_train, X_valid, y_train, y_valid = train_test_split(X, y, test_size=0.2, random_state=42) # 定义模型 model = xgb.XGBRegressor() # 定义要搜索的超参数范围 param_grid = { 'n_estimators': [50, 100, 200], 'max_depth': [3, 4, 5], 'learning_rate': [0.1, 0.01, 0.001] } # 网格搜索调参 grid = GridSearchCV(model, param_grid, scoring='neg_mean_squared_error', cv=5) grid.fit(X_train, y_train) # 输出最佳参数和最佳得分 print("Best Parameters: ", grid.best_params_) print("Best Score: ", -grid.best_score_) # 使用最佳参数的模型进行预测 best_model = grid.best_estimator_ y_pred = best_model.predict(X_valid) # 计算均方误差 mse = mean_squared_error(y_valid, y_pred) print("Mean Squared Error: ", mse) ``` 在这个示例中,我们首先导入了必要的库,包括xgboost、sklearn.datasets等。然后我们使用`load_boston`函数载入一个波士顿房价的数据集,并将其划分为训练集和验证集。 接下来,我们定义了一个XGBoost回归模型,并定义了我们要搜索的超参数范围。在这个示例中,我们搜索了三个超参数:n_estimators(弱学习器的个数)、max_depth(树的最大深度)和learning_rate(学习率)。 然后,我们使用`GridSearchCV`函数进行网格搜索调参。其中,`scoring`参数指定了评估指标(负均方误差),`cv`参数指定了交叉验证的折数。 最后,我们输出了最佳参数和最佳得分。然后,使用最佳参数的模型进行预测,并计算了均方误差。 这是一个简单的示例,实际调参可能需要更的超参数和更复杂的搜索策略,但以上代码可以作为一个起点帮助你进行XGBoost模型调参。 ### 回答3: xgboost是一种强大的机器学习模型,但在使用过程中需要调参来优化模型的性能。下面是一个关于xgboost机器学习模型调参的Python代码示例: ```python import xgboost as xgb from sklearn.datasets import load_boston from sklearn.model_selection import train_test_split from sklearn.metrics import mean_squared_error from sklearn.model_selection import GridSearchCV # 载入数据 boston = load_boston() X, y = boston.data, boston.target # 划分训练集和测试集 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) # 构建xgb模型 xgbr = xgb.XGBRegressor() # 设置需要调参的参数 parameters = {'nthread': [4], 'objective': ['reg:squarederror'], 'learning_rate': [0.1, 0.01], 'max_depth': [3, 5, 7], 'min_child_weight': [1, 3, 5], 'subsample': [0.6, 0.8], 'colsample_bytree': [0.6, 0.8], 'n_estimators': [100, 200] } # 使用GridSearchCV进行调参 grid_search = GridSearchCV(estimator=xgbr, param_grid=parameters, scoring='neg_mean_squared_error', cv=5, n_jobs=-1) grid_search.fit(X_train, y_train) # 输出最佳参数和最佳得分 best_parameters = grid_search.best_params_ best_score = grid_search.best_score_ print("Best parameters: ", best_parameters) print("Best score: ", best_score) # 使用最佳参数训练模型 xgbr_best = xgb.XGBRegressor(**best_parameters) xgbr_best.fit(X_train, y_train) # 预测并计算均方误差 y_pred = xgbr_best.predict(X_test) mse = mean_squared_error(y_test, y_pred) print("Mean Squared Error: ", mse) ``` 以上代码使用了xgboost模型对波士顿房价数据进行预测,通过GridSearchCV调参获取最佳参数,并使用最佳参数训练模型,最后输出了预测结果的均方误差。你可以根据自己的需要,根据实际情况修改代码中的参数范围和评估指标。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山鬼谣me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值