conda 安装并激活到指定目录
conda create -p /mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/envs/lavis-ganshu python=3.8
conda activate /mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/envs/lavis-ganshu
conda activate /mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/envs/llama-ganshu
/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/
ssh moxiaolin@jumper.sankuai.com
初始密码
76+@koIb)vVmYtLC
密码更改
登陆到跳板机直接输入password修改即可
jupyter notebook.
jupyter lab --config /home/hadoop-search/.jupyter/jupyter_notebook_config_ganshu.py
# hope 配置
卸载历史安装:pip uninstall hope -y
首次安装:pip install -i http://pypi.sankuai.com/simple/ hope --trusted-host pypi.sankuai.com
更新:pip install -i http://pypi.sankuai.com/simple/ hope --trusted-host pypi.sankuai.com --upgrade
streamlit run web_blip.py --server.port=8415
显存内存计算代码
from accelerate import Accelerator
import gc
import psutil
import torch
import threading
import numpy as np
def b2mb(x):
return int(x / 2**20)
class TorchTracemalloc:
def __enter__(self):
gc.collect()
torch.cuda.empty_cache()
torch.cuda.reset_max_memory_allocated() # reset the peak gauge to zero
self.begin = torch.cuda.memory_allocated()
self.process = psutil.Process()
self.cpu_begin = self.cpu_mem_used()
self.peak_monitoring = True
peak_monitor_thread = threading.Thread(target=self.peak_monitor_func)
peak_monitor_thread.daemon = True
peak_monitor_thread.start()
return self
def cpu_mem_used(self):
"""get resident set size memory for the current process"""
return self.process.memory_info().rss
def peak_monitor_func(self):
self.cpu_peak = -1
while True:
self.cpu_peak = max(self.cpu_mem_used(), self.cpu_peak)
# can't sleep or will not catch the peak right (this comment is here on purpose)
# time.sleep(0.001) # 1msec
if not self.peak_monitoring:
break
def __exit__(self, *exc):
self.peak_monitoring = False
gc.collect()
torch.cuda.empty_cache()
self.end = torch.cuda.memory_allocated()
self.peak = torch.cuda.max_memory_allocated()
self.used = b2mb(self.end - self.begin)
self.peaked = b2mb(self.peak - self.begin)
self.cpu_end = self.cpu_mem_used()
self.cpu_used = b2mb(self.cpu_end - self.cpu_begin)
self.cpu_peaked = b2mb(self.cpu_peak - self.cpu_begin)
# print(f"delta used/peak {self.used:4d}/{self.peaked:4d}")
from numpy import mean
import torch
import inspect
from torchvision import models
device = torch.device('cuda:0')
accelerator = Accelerator()
with TorchTracemalloc() as tracemalloc:
model, vis_processors, _ = load_model_and_preprocess(name="blip_caption", model_type="base_coco", is_eval=True, device=device)
ls =["/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu1.jpg"]
memory = []
for l in ls:
raw_image = Image.open(l).convert("RGB")
image = vis_processors["eval"](raw_image).unsqueeze(0).to(device)
res=model.generate({"image": image})
accelerator.print("GPU Memory before entering the train : {}".format(b2mb(tracemalloc.begin)))
accelerator.print("GPU Memory consumed at the end of the train (end-begin): {}".format(tracemalloc.used))
accelerator.print("GPU Peak Memory consumed during the train (max-begin): {}".format(tracemalloc.peaked))
accelerator.print("GPU Total Peak Memory consumed during the train (max): {}".format(tracemalloc.peaked + b2mb(tracemalloc.begin)
)
)
accelerator.print("CPU Memory before entering the train : {}".format(b2mb(tracemalloc.cpu_begin)))
accelerator.print("CPU Memory consumed at the end of the train (end-begin): {}".format(tracemalloc.cpu_used))
accelerator.print("CPU Peak Memory consumed during the train (max-begin): {}".format(tracemalloc.cpu_peaked))
accelerator.print(
"CPU Total Peak Memory consumed during the train (max): {}".format(
tracemalloc.cpu_peaked + b2mb(tracemalloc.cpu_begin)
)
)
##
from numpy import mean
import torch
import inspect
import time
from torchvision import models
device = torch.device('cuda:1')
neicun = []
xiancun = []
time_taken = []
ls =["/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu1.jpg","/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu2.jpg","/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu3.jpg","/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu4.jpg","/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu5.jpg","/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu6.jpg","/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu7.jpg","/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu8.jpg", "/mnt/dolphinfs/hdd_pool/docker/user/hadoop-search/ganshu01/projects/LAVIS-main/docs/_static/ganshu9.jpg",]
for l in ls:
with TorchTracemalloc() as tracemalloc:
start_time = time.time()
raw_image = Image.open(l).convert("RGB")
model, vis_processors, _ = load_model_and_preprocess(name="blip2_t5", model_type='caption_coco_flant5xl', is_eval=True, device=device)
image = vis_processors["eval"](raw_image).unsqueeze(0).to(device)
res=model.generate({"image": image})
end_time = time.time()
time_taken.append(end_time-start_time)
neicun.append(tracemalloc.cpu_peaked)
xiancun.append(tracemalloc.peaked)
print('xiancun:', xiancun)
print('neicun:', neicun)
print('time',time_taken)
print('mean_xiancun:', mean(xiancun))
print('mean_neicun:', mean(neicun))
print('mean_time:', mean(time_taken))
nohup jupyter notebook --port=8418 --config /home/hadoop-search/.jupyter/jupyter_notebook_config_ganshu.py > ganshu.log 2>&1 &
jupyter kernelspec list
jupyter kernelspec remove llama-ganshu
python -m ipykernel install --user --name llama-ganshu --display-name 'llama'
外网代理
# 添加proxy
export http_proxy=http://10.22.139.49:6666
export https_proxy=http://10.22.139.49:6666
#验证
echo $http_proxy
#发送一条请求
curl "http://jaminzhang.github.io/nginx/Nginx-resolver-DNS-resolve-timed-out-problem-analysis-and-solve/"
netstat -anp | grep 8418