赞
踩
- 整体来说,今年扬州办得不错,物资丰富,观众热情,加之天气锦上添花,极大扭转去年不利的印象。今天下肢酸痛,集中在大腿前侧和右脚踝,遂休整一日,明日返沪。因为昨天拉伸是在接驳车上进行,不够充分,交通管制,老爹懒得绕路来终点接我,我也是服了。
- 中国马拉松官方网站上可以查成绩,LXY芜湖10K,净时间48’58",枪声49’36",前半程24’50",后半程24’08",全程负配速,不说是竭尽全力,也算是养老慢跑。或许是状态不好,也可能是生理原因,至少我觉得她全力一定是能跑进45分钟。
- 手头还有一份2018级以前的本科生身份信息文件,顺手查了几个人的PB:
- AK:20场比赛,恐怖如斯,半马1:13:56(2019新江湾城,他来过两次扬州,分别跑出125和120),全马2:41:05(2019哈尔滨)
- WXY:半马1:24:24(2021南京仙林),全马3:23:46(2023成都)
- MK(前队):半马1:30:18(2018扬州),全马3:20:15(2019无锡)
- 五年前的AK和MK,三年前的WXY和WBJ,如今的嘉伟和我,可以算是现役中长双子星。我的群昵称一直是陈嘉伟老粉,嘉伟前两年飞速的进步,我却停滞不前,他的有氧域配速一度比我快近30秒,鸿沟般的差距,一年多来依然愿意带着我训练。去年夏训,4’05"的配速,我气喘吁吁说不上话,他却和GZY谈笑风生,让我汗颜。如今,我终于能跟他掰一下手腕。希望在一次比赛中,正面击败嘉伟,将是我对他最大的敬意。
顺手写个爬虫,从中国马拉松官网上抓一下看看目前上财历届校友的马拉松成绩,暂缺滑动验证的模拟,可以使用ActionChains实现,如:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome() # 启动浏览器驱动
driver.get("http://example.com") # 打开网页
element = driver.find_element_by_id("element_id") # 定位元素
ActionChains(driver).move_to_element(element).perform() # 使用ActionChains模拟鼠标移动到元素上
driver.quit()
关键的方法:
click(on_element=None) ——单击鼠标左键
click_and_hold(on_element=None) ——点击鼠标左键,不松开
context_click(on_element=None) ——点击鼠标右键
double_click(on_element=None) ——双击鼠标左键
drag_and_drop(source, target) ——拖拽到某个元素然后松开
drag_and_drop_by_offset(source, xoffset, yoffset) ——拖拽到某个坐标然后松开
key_down(value, element=None) ——按下某个键盘上的键
key_up(value, element=None) ——松开某个键
move_by_offset(xoffset, yoffset) ——鼠标从当前位置移动到某个坐标
move_to_element(to_element) ——鼠标移动到某个元素
move_to_element_with_offset(to_element, xoffset, yoffset) ——移动到距某个元素(左上角坐标)多少距离的位置
perform() ——执行链中的所有动作
release(on_element=None) ——在某个元素位置松开鼠标左键
send_keys(*keys_to_send) ——发送某个键到当前焦点的元素
send_keys_to_element(element, *keys_to_send) ——发送某个键到指定元素
模拟代码:
# -*- coding: utf-8 -*- # @author: caoyang # @email: caoyang@stu.sufe.edu.cn import re import time from bs4 import BeautifulSoup from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait url_host = "https://www.runchina.org.cn/" def initialize_driver(): # 初始化浏览器驱动 driver = webdriver.Chrome(chrome_options=chrome_options) driver.set_page_load_timeout(15) driver.maximize_window() return driver # 姓名和身份证号的生成器 def generate_name_and_id(): regex = re.compile("身份证,\d{17}[\dX]") data_path = r"D:\$old\studentInfo.csv" with open(data_path, 'r', encoding="utf8") as f: while True: line = f.readline() if not line: break name = line.split(',', 2)[1] matched_results = regex.findall(line) if matched_results: id_ = matched_results[0][-18: ] else: id_ = None yield name, id_ def score_query(): url_score_query = url_host + "#/data/data-mgt/score-query" xpath_input_box_name = "//div[@placeholder=\"请填写您的证件姓名\"]" xpath_input_box_id = "//div[@placeholder=\"请填写您的证件号码\"]" xpath_scroll_button = "//div[@class=\"icon nc-iconfont icon-slide-arrow\"]" # 用于验证的按钮 xpath_send_button = "//p[@class=\"search_button\"]" # 提交按钮 # TODO: 拖动滑动验证的按钮并右移松开 def _click_and_move(_driver): NotImplemented for name, id_ in generate_name_and_id(): driver = initialize_driver() driver.get(url_score_query) driver.find_element_by_xpath(xpath_input_box_name).send_keys(name) driver.find_element_by_xpath(xpath_input_box_id).send_keys(id_) _click_and_move(driver) driver.find_element_by_xpath(xpath_send_button).send_keys(id_) results = is_achievement_container_existed() with open("grade.txt", 'a', encoding="utf8") as f: f.write(f"{id_}\t{results}\n") driver.quit() # 判断是否有成绩 # TODO: 有成绩的条件下,寻找PB成绩,或返回所有成绩 def is_achievement_container_existed(driver): xpath_1 = "//div[@class=\"achievement_container\"]" if driver.find_element_by_xpath(xpath_1) is not None: return True else: return False if __name__ == "__main__": score_query()
- 最近两天状态非常低落,无关人和事,单纯因为精力耗尽,以及作息饮食紊乱:
- 31号本来就没睡多久,赛后又马不停蹄地开车带老爹回乡下把清明的事提前办了,下午到家已经快三点,时间太晚不想补觉,一直挨到晚上十一点才睡,手表显示身体电量只剩3%,困乏到了极致。
- 但昨天又不到七点就醒了,脚踝疼痛,一天没出门,这人一懒就容易贪食,吃了一堆零食(甜食是真的毒品,吃了整整一包山楂卷和四块巧克力糖,我忌口了三个月,只在饭点猛吃,昨天一破戒就停不下来了),晚上做了些核心训练才让负罪感稍减了些,但今天明显身体就有笨重感,吃饭都不香了。
- 今天右脚踝依然疼痛,只能用后跟跑,前掌跑完全支撑不住。组会前去操场,嘉伟27圈@3’40",我就顺便带着XR做力量训练(正好已两周没有力量训练),负重箭步30个×8组(+20kg),XR因为是第一次做,给他拿了块10kg的片先试试,看起来歪歪扭扭特别吃力,跟我刚进队时一模一样(那时也觉得10kg很重,现在20kg都没啥感觉了),没有人生而强大,都是从弱小慢慢成长起来,不过他这小子野心倒挺大,想今年就把5000米跑进18分半,这个成绩对我来说都不算容易(不过,假如有嘉伟带我跑,我有把握全盛状态下破开18分大关)。
X = np.linspace(0, 6, 500) std = 1 mean = 0 lognorm_distribution = stats.lognorm([std], loc=mean) lognorm_distribution_pdf = lognorm_distribution.pdf(X) fig, ax = plt.subplots(figsize=(8, 5)) plt.plot(X, lognorm_distribution_pdf, label="μ=0, σ=1") ax.set_xticks(np.arange(min(X), max(X))) std = 0.5 mean = 0 lognorm_distribution = stats.lognorm([std], loc=mean) lognorm_distribution_pdf = lognorm_distribution.pdf(X) plt.plot(X, lognorm_distribution_pdf, label="μ=0, σ=0.5") std = 1.5 mean = 1 lognorm_distribution = stats.lognorm([std], loc=mean) lognorm_distribution_pdf = lognorm_distribution.pdf(X) plt.plot(X, lognorm_distribution_pdf, label="μ=1, σ=1.5") plt.title("Lognormal Distribution") plt.legend() plt.show()
- 脚踝走路已经无碍,感觉自己又行了。下午四点去操场想试着前掌跑会儿,还是疼得厉害,脚踝依然无法承重。正好韬哥在冲3000米,配速3’50",气喘吁吁,他可是1500米能跑到4’45"以内的,这学期忙着实习,是真的虚了唉。
- 拉了几组单杠,陪韬哥摇了两圈就撤了。晚上NRC在跑百巷有活动,由于上周六开营仪式没去参加,我想着还是不能翘得太狠,正好去把衣服鞋子拿一下,骑车来回25km也算是恢复训练(主要是坐地铁还没骑车快,杨浦到静安这条线确实不方便)。AK晚上下班回来带着四五个小朋友一起跑,跟我讲这样挺好,其实学校里能跑的人还是有的,而且女生也有,下次去捞几个来平衡一下群里的男女比例。
- 首马临近,伤痛迟迟未愈,有些不顺心。4月14日的江阴半马大概还是要去的,就当是首马前的一次长距离拉练,也确实没去过江阴,也便是去游玩两日。依然没有人陪我一起,江阴这场我可以给别人当一回私兔,或许遇到有缘人,带ta跑一程吧。
其他几个常用分布:
# 泊松分布 from scipy import stats print(stats.poisson.pmf(k=9, mu=3)) X = stats.poisson.rvs(mu=3, size=500) plt.subplots(figsize=(8, 5)) plt.hist(X, density=True, edgecolor="black") plt.title("Poisson Distribution") plt.show() # 指数分布 X = np.linspace(0, 5, 5000) exponetial_distribtuion = stats.expon.pdf(X, loc=0, scale=1) plt.subplots(figsize=(8,5)) plt.plot(X, exponetial_distribtuion) plt.title("Exponential Distribution") plt.show() # 二项分布 X = np.random.binomial(n=1, p=0.5, size=1000) plt.subplots(figsize=(8, 5)) plt.hist(X) plt.title("Binomial Distribution") plt.show() # t分布 import seaborn as sns from scipy import stats X1 = stats.t.rvs(df=1, size=4) X2 = stats.t.rvs(df=3, size=4) X3 = stats.t.rvs(df=9, size=4) plt.subplots(figsize=(8,5)) sns.kdeplot(X1, label = "1 d.o.f") sns.kdeplot(X2, label = "3 d.o.f") sns.kdeplot(X3, label = "6 d.o.f") plt.title("Student's t distribution") plt.legend() plt.show() # 卡方分布 X = np.arange(0, 6, 0.25) plt.subplots(figsize=(8, 5)) plt.plot(X, stats.chi2.pdf(X, df=1), label="1 d.o.f") plt.plot(X, stats.chi2.pdf(X, df=2), label="2 d.o.f") plt.plot(X, stats.chi2.pdf(X, df=3), label="3 d.o.f") plt.title("Chi-squared Distribution") plt.legend() plt.show()
- 停跑4天,本来计划清明节是要跑一个30-35K,这样看至少要停跑一周,只用不到两周时间能恢复到破三的能力么,感觉真的很困难。
- 最近几天的活动消耗低得可怕,今天好不容易才上到800C以上。下午找嘉伟练了会儿球,感觉体力都变差了。年后其实还没跟嘉伟打过,虽然依然不是对手,但是明显要比之前好多了。
- 巅峰之后总是低谷,慢慢来吧,也不必太焦虑,总会跑得起来的。
审稿人通常会有以下几类问题针对不同问题我们可以有不同的回答模板。
切记:一定展现出诚意,虚心回答,point by point,不要刻意回避某些问题。
补充实验/仿真模拟类:
这类问题通常都很复杂,切忌回避问题。真的要做到点到点回答。你所要回避的问题审稿人都能发现。所以即使我们现有条件解决不了,我们也要向审稿人承认。不要自欺欺人。
我感觉对面一些
Thank you for suggesting the addition of experimental data. We have conducted the experiments as advised, and the results indeed align with the theoretical expectations. Thank you for............We appreciate your recommendation to include supplementary experiments. The results obtained are in line with the theoretical predictions, confirming our initial hypothesis. Thank you for............Following your suggestion, we have carried out additional experiments. The results obtained are consistent with the theoretical framework, supporting our conclusions. Thank you for............We have conducted the recommended experiments, and the results obtained confirm the anticipated outcomes based on the theoretical assumptions. Thank you for guiding us in this direction. Thank you for............Upon conducting the supplementary experiments as suggested, we found that the results align closely with the theoretical expectations. Your advice proved to be invaluable in strengthening our research. Thank you for emphasizing the importance of additional experiments. The results obtained are in accordance with the theoretical predictions, further solidifying the validity of our findings. Thank you for............We have taken your feedback into consideration and conducted the recommended experiments. The results obtained match the theoretical expectations outlined in the paper, providing robust support for our arguments. Thank you for............The additional experiments performed as per your suggestion have yielded results that are in line with the theoretical predictions. Thank you for prompting us to further validate our findings through experimentation. Thank you for............Based on your recommendation, we have carried out supplementary experiments. The results obtained are consistent with the theoretical framework proposed in the paper, reinforcing the validity of our research. Thank you for............We have followed your advice and conducted the supplementary experiments. The results obtained support the theoretical expectations outlined in our study. Your guidance has been instrumental in enhancing the rigor of our research.
- 这两天高强度打球,下午两点又陪王京练一小时球,我本以为现在打得勉强能看,但真特么随便来个人都能虐我,计分四把,全是大比分输,绷不住一点。
- 好消息是今天终于能跑起来了,右脚可以单脚踮起。午饭后去操场小憩,阳光明媚,气温也不是很高,今年清明节确实是出行的好天气。起来慢跑,配速4’19",但是六圈后,右脚踝还是明显疼痛,还是不勉强。拉了几组单杠,坐两组提踵结束,
- 晚上火车头体育场NRC训练,精英组400米@1’20"(间歇60秒),大概有10个人全程跟完课表(精英组基本上是全马245到300水平的)。我原计划签个完,量力而行,跟个几组就提前溜,毕竟白天消耗已经挺大,而且脚伤尚不明确,但是跟高手一起跑就明显兴奋得很,课表圈速是1’22"-1’28",但是众所周知一群人是没有诚信可言的,前面几个带队的很快就把圈速拉到1’20"以内,神奇的是,我居然并不吃力(已经停跑四天)。
- 10组之后,我确信自己一定可以顶完20组,此时教练提醒再这么快就要给你们加量了,一个个老实了点。最后五组,我觉得自己有余力,开始跟着第一集团猛冲,分别跑出1’17",1’13"(从最后一位超到第一位),1’17",1’20"(这一组收着了,留给最后一组冲刺),1’13"的圈速,一位大哥在我后面喊,最前面那位是谁,这么猛?步伐真大,冲过来我都害怕,给诸位一点小小的震撼。(要是嘉伟能来,指定降维打击。嘉伟这次锡马真是越想越可惜,能进245真就圆满了)。
- 今日活动消耗1700C+,持平31号扬马那日的活动消耗,极大地扭转了前四日不振的状态。400米间歇确是极好的恢复训练(进入状态后越跑越轻松,以前下班回来就算再累,12组400米变速也能轻松跑完),我确信已基本恢复到全盛状态。接下来就是无伤坚持到首马开赛,我已做好付出代价的准备(这次半马确实顶到极限,脚踝应该是肌肉疲劳,损伤多少也有,可想而知全马如果顶到极限,肯定不会是无伤),哪怕最后只能跪着爬回来。
GaLore在本地GPU进行LLM调优:
安装依赖
pip install galore-torch
datasets==2.18.0
transformers==4.39.1
trl==0.8.1
accelerate==0.28.0
torch==2.2.1
调度优化器类:
from typing import Optional import torch # Approach taken from Hugging Face transformers https://github.com/huggingface/transformers/blob/main/src/transformers/optimization.py class LayerWiseDummyOptimizer(torch.optim.Optimizer): def __init__(self, optimizer_dict=None, *args, **kwargs): dummy_tensor = torch.randn(1, 1) self.optimizer_dict = optimizer_dict super().__init__([dummy_tensor], {"lr": 1e-03}) def zero_grad(self, set_to_none: bool = True) -> None: pass def step(self, closure=None) -> Optional[float]: pass class LayerWiseDummyScheduler(torch.optim.lr_scheduler.LRScheduler): def __init__(self, *args, **kwargs): optimizer = LayerWiseDummyOptimizer() last_epoch = -1 verbose = False super().__init__(optimizer, last_epoch, verbose) def get_lr(self): return [group["lr"] for group in self.optimizer.param_groups] def _get_closed_form_lr(self): return self.base_lrs
加载GaLore优化器对象
from transformers import get_constant_schedule from functools import partial import torch.nn import bitsandbytes as bnb from galore_torch import GaLoreAdamW8bit def load_galore_optimizer(model, lr, galore_config): # function to hook optimizer and scheduler to a given parameter def optimizer_hook(p, optimizer, scheduler): if p.grad is not None: optimizer.step() optimizer.zero_grad() scheduler.step() # Parameters to optimize with Galore galore_params = [ (module.weight, module_name) for module_name, module in model.named_modules() if isinstance(module, nn.Linear) and any(target_key in module_name for target_key in galore_config["target_modules_list"]) ] id_galore_params = {id(p) for p, _ in galore_params} # Hook Galore optim to all target params, Adam8bit to all others for p in model.parameters(): if p.requires_grad: if id(p) in id_galore_params: optimizer = GaLoreAdamW8bit([dict(params=[p], **galore_config)], lr=lr) else: optimizer = bnb.optim.Adam8bit([p], lr = lr) scheduler = get_constant_schedule(optimizer) p.register_post_accumulate_grad_hook(partial(optimizer_hook, optimizer=optimizer, scheduler=scheduler)) # return dummies, stepping is done with hooks return LayerWiseDummyOptimizer(), LayerWiseDummyScheduler()
- 昨晚练完就很奇怪,为什么中午慢跑6圈就觉得右脚踝酸得受不了,但是到晚上,明明消耗更大,骑到火车头时,身体感觉很疲劳,不像是能上得了强度的状态,但20组400米间歇就是硬顶了下来,右脚踝一点事都没有。今天想趁热打铁,跑个30K,感觉昨天休息得很好,首马前也急缺长距离拉练。
- 但只跑了4K,脚踝就有些受不了,大失所望,后面去操场冲了三组400米间歇,反而很轻松,我想可能是触地时间的区别,脚踝耐受也确实不行了,不知还要多久才能恢复到之前的状态。
- 晚饭后补了8组×30箭步(+20kg),也明显比4月2日那天做得吃力,这两天越来越吃不准状态。回楼想要再跳会儿绳,试图小强度恢复脚踝力量,跳了几十个后,决心还是放弃。
- 真的止于三月了,吗?
- 我不甘心
HF Trainer
from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments, set_seed, get_constant_schedule from trl import SFTTrainer, setup_chat_format, DataCollatorForCompletionOnlyLM from datasets import load_dataset import torch, torch.nn as nn, uuid, wandb lr = 1e-5 # GaLore optimizer hyperparameters galore_config = dict( target_modules_list = ["attn", "mlp"], rank = 1024, update_proj_gap = 200, scale = 2, proj_type="std" ) modelpath = "meta-llama/Llama-2-7b" model = AutoModelForCausalLM.from_pretrained( modelpath, torch_dtype=torch.bfloat16, attn_implementation = "flash_attention_2", device_map = "auto", use_cache = False, ) tokenizer = AutoTokenizer.from_pretrained(modelpath, use_fast = False) # Setup for ChatML model, tokenizer = setup_chat_format(model, tokenizer) if tokenizer.pad_token in [None, tokenizer.eos_token]: tokenizer.pad_token = tokenizer.unk_token # subset of the Open Assistant 2 dataset, 4000 of the top ranking conversations dataset = load_dataset("g-ronimo/oasst2_top4k_en") training_arguments = TrainingArguments( output_dir = f"out_{run_id}", evaluation_strategy = "steps", label_names = ["labels"], per_device_train_batch_size = 16, gradient_accumulation_steps = 1, save_steps = 250, eval_steps = 250, logging_steps = 1, learning_rate = lr, num_train_epochs = 3, lr_scheduler_type = "constant", gradient_checkpointing = True, group_by_length = False, ) optimizers = load_galore_optimizer(model, lr, galore_config) trainer = SFTTrainer( model = model, tokenizer = tokenizer, train_dataset = dataset["train"], eval_dataset = dataset['test'], data_collator = DataCollatorForCompletionOnlyLM( instruction_template = "<|im_start|>user", response_template = "<|im_start|>assistant", tokenizer = tokenizer, mlm = False), max_seq_length = 256, dataset_kwargs = dict(add_special_tokens = False), optimizers = optimizers, args = training_arguments, ) trainer.train()
- 一日细雨,似是清明大好天气的代价,好像给了我偷懒的理由。
- 扬马市民前十出炉,瞋目结舌,除E区杀出个程咬金,其余九位全是A区大佬,第一1:15:38,第十1:20:36,往年120已是市民第一的水平,今年竟然连前十都悬,这两年大众水平进步太大,之前还以为稳进前十,沾沾自喜,到头来小丑竟是我自己
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/568284
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。