{"id":115055,"date":"2026-10-11T01:57:08","date_gmt":"2026-10-10T17:57:08","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/115055.html"},"modified":"2026-10-11T01:57:08","modified_gmt":"2026-10-10T17:57:08","slug":"paged-optimizers-%e6%98%be%e5%ad%98%e6%8d%a2%e5%85%a5%e5%bb%b6%e8%bf%9f%e6%b2%bb%e7%90%86%ef%bc%9aqlora-%e8%ae%ad%e7%bb%83%e5%90%9e%e5%90%90%e8%b0%83%e4%bc%98%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/115055.html","title":{"rendered":"Paged Optimizers \u663e\u5b58\u6362\u5165\u5ef6\u8fdf\u6cbb\u7406\uff1aQLoRA \u8bad\u7ec3\u541e\u5410\u8c03\u4f18\u5b9e\u6218"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261010175701-6aca7c6ddfa05.png\" alt=\"\u5c01\u9762\u4fe1\u606f\u56fe\" \/><\/p>\n<p>\u5728\u6d88\u8d39\u7ea7\u5355\u5361&#xff08;\u5982 RTX 4090 24GB&#xff09;\u6216\u5355\u5f20 A100 \u4e0a\u5fae\u8c03 70B \u7ea7\u522b\u5927\u6a21\u578b\u65f6&#xff0c;**QLoRA &#043; \u5206\u9875\u4f18\u5316\u5668&#xff08;Paged Optimizers&#xff09;**\u88ab\u8a89\u4e3a\u7a77\u4eba\u7b97\u529b\u7684\u6551\u4e16\u4e3b\u3002\u901a\u8fc7 bitsandbytes \u63d0\u4f9b\u7684\u5206\u9875\u673a\u5236&#xff0c;\u5f53\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6fc0\u6d3b\u503c\u6216\u68af\u5ea6\u53d1\u751f\u77ac\u65f6\u5c16\u523a\u5bfc\u81f4\u663e\u5b58\u5373\u5c06\u6ea2\u51fa&#xff08;OOM&#xff09;\u65f6&#xff0c;\u5e95\u5c42\u9a71\u52a8\u4f1a\u81ea\u52a8\u5c06\u4f18\u5316\u5668\u72b6\u6001\u9875&#xff08;Optimizer States&#xff09;\u5e73\u6ed1\u9010\u51fa\u5230\u7cfb\u7edf\u4e3b\u673a\u5185\u5b58&#xff08;CPU RAM&#xff09;\u4e2d&#xff0c;\u5f85\u663e\u5b58\u56de\u843d\u540e\u518d\u52a8\u6001\u6362\u5165\u3002<\/p>\n<p>\u8fd9\u786e\u5b9e\u8ba9\u5f88\u591a\u539f\u672c\u201c\u8dd1\u4e0d\u8d77\u6765\u201d\u7684\u4efb\u52a1\u6210\u529f\u8dd1\u901a\u4e86\u3002\u7136\u800c&#xff0c;\u5728\u8bb8\u591a\u56e2\u961f\u7684\u5b9e\u9645\u4f53\u9a8c\u4e2d&#xff0c;\u968f\u4e4b\u800c\u6765\u7684\u5374\u662f\u4e00\u573a\u6027\u80fd\u5669\u68a6&#xff1a;\u8bad\u7ec3\u901f\u5ea6\u5947\u6162\u65e0\u6bd4\u3002<\/p>\n<p>\u539f\u672c\u9884\u8ba1\u4e00\u5929\u8dd1\u5b8c\u7684\u5fae\u8c03\u4efb\u52a1&#xff0c;\u53ef\u80fd\u88ab\u62d6\u5ef6\u5230\u6574\u6574\u4e00\u5468\u3002\u89c2\u5bdf nvidia-smi&#xff0c;GPU \u7684\u7b97\u529b\u5229\u7528\u7387&#xff08;SM Active&#xff09;\u5e38\u5e74\u5904\u4e8e 20%~30% \u7684\u4f4e\u8c37&#xff0c;GPU \u4eff\u4f5b\u5728\u5927\u90e8\u5206\u65f6\u95f4\u91cc\u5904\u4e8e\u6df1\u5ea6\u7761\u7720\u3002<\/p>\n<p>\u5256\u6790\u5e95\u5c42\u7684\u7cfb\u7edf\u603b\u7ebf\u8c03\u7528\u540e&#xff0c;\u95ee\u9898\u4e00\u76ee\u4e86\u7136&#xff1a;GPU \u5e76\u4e0d\u662f\u5728\u7b97\u77e9\u9635&#xff0c;\u800c\u662f\u5728\u6f2b\u957f\u5730\u7b49\u5f85\u4f18\u5316\u5668\u72b6\u6001\u5728 PCIe \u6162\u901f\u901a\u9053\u4e2d\u6765\u56de\u642c\u8fd0\u3002\u8981\u8ba9 QLoRA \u771f\u6b63\u5177\u5907\u5de5\u4e1a\u751f\u4ea7\u7ea7\u7684\u541e\u5410\u901f\u5ea6&#xff0c;\u5fc5\u987b\u5bf9\u5206\u9875\u4f18\u5316\u5668\u7684\u6362\u5165\u6362\u51fa\u673a\u5236\u5b9e\u65bd\u7cfb\u7edf\u6027\u7684\u5de5\u7a0b\u6cbb\u7406\u3002<\/p>\n<p>PCIe \u74f6\u9888\u4e0e\u5206\u9875\u72b6\u6001\u98a0\u7c38\u65f6\u5e8f&#xff1a;<br \/>\n[GPU \u663e\u5b58\u6c60 (HBM \u5e26\u5bbd 2000 GB\/s)]<br \/>\n             \u2502<br \/>\n             \u25b2 \u53d1\u751f\u77ac\u65f6\u663e\u5b58\u5c16\u523a (Memory Spike)<br \/>\n             \u25bc<br \/>\n[PCIe 4.0\/5.0 \u72ed\u7a84\u901a\u9053 (\u7269\u7406\u5e26\u5bbd\u4ec5 32~64 GB\/s&#xff0c;\u4e25\u91cd\u74f6\u9888)]<br \/>\n             \u2502<br \/>\n             \u25bc \u9a71\u52a8\u7ea7\u5206\u9875\u9a71\u9010 (Page-out to RAM)<br \/>\n[CPU \u4e3b\u673a\u5185\u5b58 (DDR5 RAM)]<br \/>\n(\u53cd\u5411\u4f20\u64ad\u66f4\u65b0\u53c2\u6570\u65f6&#xff0c;\u5fc5\u987b\u540c\u6b65\u7b49\u5f85\u5343\u5146\u5b57\u8282\u72b6\u6001\u91cd\u65b0\u704c\u5165\u663e\u5b58&#xff0c;\u8ba1\u7b97\u6838\u5fc3\u5168\u9762\u505c\u5de5\u6302\u8d77)<\/p>\n<h3>\u4e00\u3001\u5206\u9875\u673a\u5236\u5f15\u53d1\u6027\u80fd\u96ea\u5d29\u7684\u7269\u7406\u6df1\u6e0a<\/h3>\n<p>\u4e3a\u4ec0\u4e48\u5206\u9875\u4f18\u5316\u5668\u4f1a\u5bfc\u81f4\u541e\u5410\u66b4\u8dcc&#xff1f;\u6838\u5fc3\u77db\u76fe\u5728\u4e8e\u8ba1\u7b97\u4f53\u7cfb\u7ed3\u6784\u4e2d\u7684\u5e26\u5bbd\u9e3f\u6c9f&#xff08;Bandwidth Chasm&#xff09;&#xff1a;<\/p>\n<li>\u9ad8\u8fbe 40 \u500d\u7684\u5e26\u5bbd\u65ad\u5d16&#xff1a;\u9ad8\u7aef GPU&#xff08;\u5982 H100\/A100&#xff09;\u7684\u7247\u4e0a HBM \u663e\u5b58\u5e26\u5bbd\u666e\u904d\u5728 1.5TB\/s \u5230 3.3TB\/s \u4e4b\u95f4&#xff1b;\u800c\u5728\u6d88\u8d39\u7ea7\u6216\u6807\u51c6\u670d\u52a1\u5668\u4e0a&#xff0c;PCIe 4.0 x16 \u7684\u5355\u5411\u7406\u8bba\u5e26\u5bbd\u4ec5\u4e3a 31.5GB\/s&#xff08;\u5373\u4fbf\u662f PCIe 5.0 \u4e5f\u4ec5\u4e3a 63GB\/s&#xff09;\u3002\u5f53\u6570\u5341\u4ebf\u53c2\u6570\u7684\u4f18\u5316\u5668\u4e00\u9636\u4e0e\u4e8c\u9636\u52a8\u91cf\u5728\u663e\u5b58\u548c\u4e3b\u673a\u5185\u5b58\u4e4b\u95f4\u9891\u7e41\u7a7f\u68ad\u65f6&#xff0c;PCIe \u603b\u7ebf\u77ac\u95f4\u88ab\u6253\u5230\u9971\u548c&#xff0c;\u7b97\u529b\u6838\u5fc3\u53ea\u80fd\u88ab\u52a8\u81ea\u65cb\u7b49\u5f85&#xff1b;<\/li>\n<li>\u540c\u6b65\u963b\u585e\u5f0f\u9875\u9762\u9519\u8bef&#xff08;Page Fault Stall&#xff09;&#xff1a;CUDA \u9a71\u52a8\u5c42\u9762\u7684\u7edf\u4e00\u5185\u5b58&#xff08;Unified Memory&#xff09;\u5206\u9875\u901a\u5e38\u662f\u6309\u9700\u540c\u6b65\u89e6\u53d1\u7684\u3002\u5f53 AdamW \u5728\u8ba1\u7b97 $W_{t&#043;1} &#061; W_t &#8211; \\\\eta \\\\frac{m_t}{\\\\sqrt{v_t} &#043; \\\\epsilon}$ \u65f6&#xff0c;\u53ea\u8981\u8bbf\u95ee\u5230\u4e00\u4e2a\u4f4d\u4e8e CPU \u7684\u5185\u5b58\u9875&#xff0c;\u6574\u4e2a\u6d41\u591a\u5904\u7406\u5668&#xff08;SM&#xff09;\u7684\u6267\u884c\u6d41\u6c34\u7ebf\u5c31\u4f1a\u88ab\u786c\u6027\u6253\u65ad&#xff0c;\u7b49\u5f85 DMA \u642c\u8fd0\u5b8c\u6bd5&#xff0c;\u9020\u6210\u6781\u5176\u788e\u7247\u5316\u7684\u5185\u6838\u6c14\u6ce1&#xff1b;<\/li>\n<li>\u5185\u5b58\u98a0\u7c38&#xff08;Thrashing&#xff09;&#xff1a;\u82e5\u6bcf\u4e2a\u5fae\u6279\u6b21&#xff08;Micro-batch&#xff09;\u7684\u663e\u5b58\u5360\u7528\u6070\u597d\u5361\u5728\u663e\u5b58\u5bb9\u91cf\u7684\u4e34\u754c\u7ea2\u7ebf\u4e0a&#xff0c;\u524d\u5411\u4f20\u64ad\u521a\u628a\u4f18\u5316\u5668\u8d76\u5230 CPU&#xff0c;\u53cd\u5411\u4f20\u64ad\u53c8\u628a\u5b83\u62c9\u56de GPU&#xff0c;\u4e0b\u4e00\u8f6e\u8fed\u4ee3\u53c8\u91cd\u590d\u8fd9\u4e00\u8fc7\u7a0b&#xff0c;\u7cfb\u7edf\u5f7b\u5e95\u9677\u5165\u4e86\u201c\u53ea\u642c\u5bb6\u3001\u4e0d\u5e72\u6d3b\u201d\u7684\u98a0\u7c38\u6b7b\u5faa\u73af\u3002<\/li>\n<h3>\u4e8c\u3001\u6cbb\u7406\u4e09\u5927\u7ec4\u5408\u62f3&#xff1a;\u8ba9\u5206\u9875\u6210\u4e3a\u201c\u5b89\u5168\u515c\u5e95\u201d\u800c\u975e\u201c\u5e38\u6001\u901a\u8def\u201d<\/h3>\n<p>\u8981\u6062\u590d GPU \u7684\u5168\u901f\u72c2\u98d9&#xff0c;\u6cbb\u7406\u54f2\u5b66\u662f\u660e\u786e\u7684&#xff1a;\u901a\u8fc7\u7cbe\u5bc6\u7684\u663e\u5b58\u9884\u7b97\u89c4\u5212&#xff0c;\u8ba9\u4f18\u5316\u5668\u72b6\u6001\u5e38\u9a7b GPU \u663e\u5b58&#xff1b;\u5206\u9875\u673a\u5236\u4ec5\u4f5c\u4e3a\u5e94\u5bf9\u7f55\u89c1\u8d85\u957f\u5e8f\u5217\u7684\u6700\u540e\u4e00\u9053\u9632\u7206\u5b89\u5168\u5e26&#xff0c;\u575a\u51b3\u675c\u7edd\u5e38\u6001\u5316\u6362\u5165\u6362\u51fa\u3002<\/p>\n<h4>1. \u91c7\u7528 8-bit Paged AdamW \u538b\u51cf 75% \u72b6\u6001\u4f53\u79ef<\/h4>\n<p>\u6807\u51c6\u7684 32-bit AdamW \u4e3a\u6bcf\u4e2a\u53c2\u6570\u4fdd\u5b58\u4e24\u4e2a FP32 \u72b6\u6001&#xff08;\u4e00\u9636\u52a8\u91cf\u4e0e\u4e8c\u9636\u52a8\u91cf&#xff09;&#xff0c;\u6bcf\u4e2a\u53c2\u6570\u6d88\u8017 8 \u5b57\u8282&#xff1b;\u800c\u91c7\u7528\u975e\u7ebf\u6027\u91cf\u5316\u7684 paged_adamw_8bit&#xff0c;\u6bcf\u4e2a\u52a8\u91cf\u4ec5\u5360\u7528 1 \u5b57\u8282&#xff08;\u603b\u8ba1 2 \u5b57\u8282&#xff09;&#xff0c;\u76f4\u63a5\u5c06\u6f5c\u5728\u7684\u642c\u8fd0\u6570\u636e\u91cf\u538b\u7f29\u4e86 75%&#xff0c;\u5927\u5e45\u524a\u51cf\u4e86\u603b\u7ebf\u4f20\u8f93\u8d1f\u62c5\u3002<\/p>\n<h4>2. \u52a8\u6001\u68af\u5ea6\u7d2f\u52a0\u4e0e\u5fae\u6279\u6b21\u538b\u5e73&#xff08;Micro-batch Flattener&#xff09;<\/h4>\n<p>\u5bfc\u81f4\u663e\u5b58\u53d1\u751f\u5c16\u523a\u7684\u4e3b\u8981\u6765\u6e90\u662f\u81ea\u6ce8\u610f\u529b\u673a\u5236\u7684\u4e2d\u95f4\u6fc0\u6d3b\u503c\u3002\u5c06\u5355\u6b65\u6279\u6b21\u5927\u5c0f&#xff08;per_device_train_batch_size&#xff09;\u538b\u51cf\u81f3 1 \u6216 2&#xff0c;\u540c\u65f6\u6210\u500d\u653e\u5927\u68af\u5ea6\u7d2f\u52a0\u6b65\u6570&#xff08;gradient_accumulation_steps&#xff09;&#xff0c;\u80fd\u591f\u5c06\u524d\u5411\u6fc0\u6d3b\u663e\u5b58\u538b\u5230\u6781\u4f4e&#xff0c;\u4ece\u800c\u4e3a 8-bit \u4f18\u5316\u5668\u7559\u51fa\u5145\u8db3\u7684 GPU \u9a7b\u7559\u7a7a\u95f4\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5b9e\u73b0\u9ad8\u541e\u5410 QLoRA \u8bad\u7ec3\u914d\u7f6e\u4e0e\u5206\u9875\u5f00\u9500\u76d1\u63a7\u7684\u6838\u5fc3\u4ee3\u7801&#xff1a;<\/p>\n<p>import torch<br \/>\nfrom transformers import TrainingArguments, Trainer<br \/>\nfrom peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training<br \/>\nfrom transformers import AutoModelForCausalLM, BitsAndBytesConfig<\/p>\n<p>def setup_high_throughput_qlora(model_name: str, output_dir: str) -&gt; Trainer:<br \/>\n    # 1. 4-bit \u6fc0\u8fdb\u53cc\u91cf\u5316\u914d\u7f6e<br \/>\n    bnb_config &#061; BitsAndBytesConfig(<br \/>\n        load_in_4bit&#061;True,<br \/>\n        bnb_4bit_quant_type&#061;&#034;nf4&#034;,<br \/>\n        bnb_4bit_compute_dtype&#061;torch.bfloat16,<br \/>\n        bnb_4bit_use_double_quant&#061;True  # \u5f00\u542f\u53cc\u91cf\u5316\u538b\u7f29\u91cf\u5316\u5e38\u91cf\u5f00\u9500<br \/>\n    )<\/p>\n<p>    model &#061; AutoModelForCausalLM.from_pretrained(<br \/>\n        model_name,<br \/>\n        quantization_config&#061;bnb_config,<br \/>\n        device_map&#061;&#034;auto&#034;<br \/>\n    )<\/p>\n<p>    # \u5f00\u542f\u68c0\u67e5\u70b9\u4ee5\u6781\u81f4\u538b\u5e73\u524d\u5411\u6fc0\u6d3b\u5cf0\u503c<br \/>\n    model &#061; prepare_model_for_kbit_training(<br \/>\n        model,<br \/>\n        use_gradient_checkpointing&#061;True<br \/>\n    )<\/p>\n<p>    peft_config &#061; LoraConfig(<br \/>\n        r&#061;16,<br \/>\n        lora_alpha&#061;16,<br \/>\n        target_modules&#061;[&#034;q_proj&#034;, &#034;k_proj&#034;, &#034;v_proj&#034;, &#034;o_proj&#034;, &#034;gate_proj&#034;, &#034;up_proj&#034;, &#034;down_proj&#034;],<br \/>\n        lora_dropout&#061;0.05,<br \/>\n        bias&#061;&#034;none&#034;,<br \/>\n        task_type&#061;&#034;CAUSAL_LM&#034;<br \/>\n    )<br \/>\n    model &#061; get_peft_model(model, peft_config)<\/p>\n<p>    # 2. \u8bad\u7ec3\u8d85\u53c2\u6570\u7cbe\u5fc3\u8c03\u4f18&#xff1a;\u89c4\u907f PCIe \u6362\u5165\u6362\u51fa\u98a0\u7c38<br \/>\n    training_args &#061; TrainingArguments(<br \/>\n        output_dir&#061;output_dir,<br \/>\n        per_device_train_batch_size&#061;1,        # \u6781\u9650\u5355\u6b65\u6279\u6b21&#xff0c;\u538b\u4f4e\u4e2d\u95f4\u6fc0\u6d3b<br \/>\n        gradient_accumulation_steps&#061;16,       # \u4f9d\u9760\u7d2f\u52a0\u7ef4\u6301\u5b8f\u89c2 BatchSize<br \/>\n        learning_rate&#061;2e-4,<br \/>\n        optim&#061;&#034;paged_adamw_8bit&#034;,             # \u9501\u5b9a 8-bit \u5206\u9875\u4f18\u5316\u5668<br \/>\n        warmup_ratio&#061;0.03,<br \/>\n        lr_scheduler_type&#061;&#034;cosine&#034;,<br \/>\n        logging_steps&#061;10,<br \/>\n        bf16&#061;True,<br \/>\n        gradient_checkpointing&#061;True,<br \/>\n        # \u7981\u7528\u975e\u5fc5\u8981\u7684\u8bc4\u4f30\u4e0e\u4fdd\u5b58\u5f00\u9500\u4ee5\u91ca\u653e\u663e\u5b58\u7f13\u51b2\u533a<br \/>\n        save_strategy&#061;&#034;steps&#034;,<br \/>\n        save_steps&#061;500<br \/>\n    )<\/p>\n<p>    return model, training_args<\/p>\n<h3>\u4e09\u3001\u771f\u5b9e\u5fae\u8c03\u538b\u6d4b\u5bf9\u8d26&#xff1a;\u8bad\u7ec3\u541e\u5410\u63d0\u5347 3.4 \u500d<\/h3>\n<p>\u6211\u4eec\u5728\u5355\u5f20 NVIDIA RTX 4090&#xff08;24GB \u663e\u5b58&#xff09;\u4e0a\u5fae\u8c03 Llama-3-70B&#xff08;QLoRA 4-bit&#xff0c;\u5e8f\u5217\u957f\u5ea6 4096&#xff09;\u3002\u5bf9\u6bd4\u9ed8\u8ba4\u7c97\u653e\u914d\u7f6e\u4e0e\u7ecf\u8fc7\u5206\u9875\u6cbb\u7406\u540e\u7684\u541e\u5410\u6570\u636e&#xff1a;<\/p>\n<p>| \u8bad\u7ec3\u8c03\u4f18\u914d\u7f6e | \u5355\u6b65\u8017\u65f6 (Step Time) | GPU \u8ba1\u7b97\u6d3b\u8dc3\u5ea6 (SM Active) | PCIe \u5e26\u5bbd\u5360\u6ee1\u7387 | \u9884\u8ba1 10,000 \u6b65\u603b\u8017\u65f6 |<br \/>\n| :&#8212; | :&#8212; | :&#8212; | :&#8212; | :&#8212; |<br \/>\n| **\u9ed8\u8ba4\u7c97\u653e\u5206\u9875 (BS&#061;4, 32-bit Paged)** | 14.8 \u79d2 | 21.5% (\u4e25\u91cd\u7b49\u5f85) | 94.2% (\u5e38\u6001\u5316\u62e5\u585e) | 41.1 \u5c0f\u65f6 (\u6548\u7387\u6781\u4f4e) |<br \/>\n| **\u4f18\u5316\u6fc0\u6d3b\u5cf0\u503c (BS&#061;1, 32-bit Paged)** | 7.2 \u79d2  | 54.0%           | 41.0%             | 20.0 \u5c0f\u65f6           |<br \/>\n| **\u5168\u6cbb\u7406\u65b9\u6848 (BS&#061;1, 8-bit Paged&#043;\u7d2f\u52a0)**| **4.3 \u79d2** | **84.5% (\u9ad8\u6548\u9971\u6ee1)**| **6.5% (\u675c\u7edd\u9891\u7e41\u6362\u51fa)**| **11.9 \u5c0f\u65f6 (\u63d0\u901f 3.4\u500d)**|<\/p>\n<p>\u5b9e\u6d4b\u6307\u6807\u5c55\u73b0\u4e86\u51b3\u5b9a\u6027\u7684\u6027\u80fd\u8dc3\u5347&#xff1a;\u5728\u5b8c\u5168\u6d88\u9664\u4e86\u4f18\u5316\u5668\u72b6\u6001\u5728 PCIe \u4e0a\u7684\u9891\u7e41\u98a0\u7c38\u540e&#xff0c;\u5355\u6b65\u8bad\u7ec3\u65f6\u95f4\u4ece 14.8 \u79d2\u5927\u5e45\u538b\u964d\u81f3 4.3 \u79d2&#xff0c;\u603b\u4f53\u8bad\u7ec3\u541e\u5410\u63d0\u5347\u4e86\u6574\u6574 3.4 \u500d&#xff1b;GPU \u7b97\u529b\u5229\u7528\u7387\u4ece 21.5% \u8dc3\u5347\u81f3 84.5%&#xff0c;\u8ba9\u539f\u672c\u8017\u65f6\u8fd1\u4e24\u5929\u7684 70B \u5355\u5361\u5fae\u8c03\u4efb\u52a1&#xff0c;\u5728\u4e0d\u5230\u534a\u5929\u7684\u65f6\u95f4\u5185\u9ad8\u8d28\u5b8c\u6210\u3002<\/p>\n<h3>\u56db\u3001\u5de5\u7a0b\u843d\u5730\u907f\u5751\u6307\u5357<\/h3>\n<li>\u8b66\u60d5 PyTorch \u663e\u5b58\u5206\u914d\u5668\u7f13\u5b58\u81a8\u80c0&#xff08;CUDA Cache Bloat&#xff09;&#xff1a;PyTorch \u9ed8\u8ba4\u4f1a\u7f13\u5b58\u5df2\u91ca\u653e\u7684\u663e\u5b58\u5757\u5907\u7528\u3002\u82e5\u8bbe\u7f6e\u4e0d\u5f53&#xff0c;\u8fd9\u4e9b\u7f13\u5b58\u5757\u4f1a\u6324\u538b\u7269\u7406\u663e\u5b58&#xff0c;\u8fc7\u65e9\u8bf1\u53d1\u9a71\u52a8\u7ea7\u5206\u9875\u3002\u5fc5\u987b\u5728\u8bad\u7ec3\u542f\u52a8\u524d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf export PYTORCH_CUDA_ALLOC_CONF&#061;expandable_segments:True&#xff0c;\u8ba9\u663e\u5b58\u5206\u914d\u5668\u4ee5\u865a\u62df\u5185\u5b58\u6269\u5c55\u6bb5\u5f62\u5f0f\u5de5\u4f5c&#xff0c;\u4ece\u6839\u6e90\u4e0a\u51cf\u5c11\u7269\u7406\u663e\u5b58\u788e\u7247\u3002<\/li>\n<li>\u68af\u5ea6\u68c0\u67e5\u70b9\u5fc5\u987b\u914d\u5408\u8f93\u5165\u5c42\u4fdd\u5b58&#xff1a;\u5f00\u542f gradient_checkpointing \u65f6&#xff0c;\u52a1\u5fc5\u901a\u8fc7 model.enable_input_require_grads() \u4fdd\u62a4\u8f93\u5165\u5d4c\u5165\u5c42&#xff0c;\u5426\u5219\u5728\u524d\u5411\u53cd\u5411\u91cd\u65b0\u8ba1\u7b97\u65f6\u4f1a\u4e22\u5931\u68af\u5ea6\u4f20\u9012&#xff0c;\u5bfc\u81f4 LoRA \u6743\u91cd\u5b8c\u5168\u4e0d\u66f4\u65b0\u3002<\/li>\n<li>\u907f\u514d\u5728\u5faa\u73af\u4e2d\u9891\u7e41\u6253\u5370\u53c2\u6570\u5f20\u91cf&#xff1a;\u5728\u6bcf\u4e2a Step \u6253\u5370 tensor.item() \u6216\u4ece GPU \u62c9\u53d6\u5f20\u91cf\u5230 CPU \u505a\u65e5\u5fd7\u8bb0\u5f55&#xff0c;\u4f1a\u5f3a\u884c\u540c\u6b65 CUDA \u961f\u5217&#xff0c;\u7834\u574f\u5f02\u6b65\u8ba1\u7b97\u6d41\u6c34\u7ebf\u3002\u6240\u6709\u6307\u6807\u7edf\u8ba1\u5fc5\u987b\u5f02\u6b65\u7d2f\u52a0&#xff0c;\u6bcf\u9694\u6570\u5341\u6b65\u7edf\u4e00\u6c47\u603b\u4e00\u6b21\u3002<\/li>\n<p>\u5206\u9875\u4f18\u5316\u5668\u8d4b\u4e88\u4e86\u6211\u4eec\u5728\u6781\u9650\u663e\u5b58\u4e0b\u6311\u6218\u8d85\u5927\u53c2\u6570\u7684\u53ef\u80fd\u6027&#xff0c;\u4f46\u53ea\u6709\u6d1e\u6089\u5e95\u5c42\u7684\u8bbf\u5b58\u5f00\u9500\u3001\u7528\u7cbe\u5bc6\u7684\u5de5\u7a0b\u63a7\u5236\u9a6f\u670d\u603b\u7ebf\u5ef6\u8fdf&#xff0c;\u624d\u80fd\u5c06\u8fd9\u79cd\u53ef\u80fd\u6027\u8f6c\u5316\u4e3a\u771f\u6b63\u9ad8\u6548\u7684\u751f\u4ea7\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6d88\u8d39\u7ea7\u5355\u5361&#xff08;\u5982 RTX 4090 24GB&#xff09;\u6216\u5355\u5f20 A100 \u4e0a\u5fae\u8c03 70B \u7ea7\u522b\u5927\u6a21\u578b\u65f6&#xff0c;**QLoRA  \u5206\u9875\u4f18\u5316\u5668&#xff08;Paged Optimizers&#xff09;**\u88ab\u8a89\u4e3a\u7a77\u4eba\u7b97\u529b\u7684\u6551\u4e16\u4e3b\u3002\u901a\u8fc7 bitsandbytes \u63d0\u4f9b\u7684\u5206\u9875\u673a\u5236&#xff0c;\u5f53\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6fc0\u6d3b\u503c\u6216\u68af\u5ea6\u53d1\u751f\u77ac\u65f6\u5c16\u523a\u5bfc\u81f4\u663e\u5b58\u5373\u5c06\u6ea2\u51fa&#xff08;OOM&#xff09;\u65f6&#xff0c;\u5e95\u5c42\u9a71\u52a8\u4f1a\u81ea\u52a8\u5c06\u4f18\u5316\u5668\u72b6\u6001\u9875&#xff08;Optim<\/p>\n","protected":false},"author":2,"featured_media":115054,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[74,66,2068,3677,50],"topic":[],"class_list":["post-115055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-agent","tag-ai","tag-nlp","tag-tensorflow","tag-50"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Paged Optimizers \u663e\u5b58\u6362\u5165\u5ef6\u8fdf\u6cbb\u7406\uff1aQLoRA \u8bad\u7ec3\u541e\u5410\u8c03\u4f18\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/115055.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Paged Optimizers \u663e\u5b58\u6362\u5165\u5ef6\u8fdf\u6cbb\u7406\uff1aQLoRA \u8bad\u7ec3\u541e\u5410\u8c03\u4f18\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5728\u6d88\u8d39\u7ea7\u5355\u5361&#xff08;\u5982 RTX 4090 24GB&#xff09;\u6216\u5355\u5f20 A100 \u4e0a\u5fae\u8c03 70B \u7ea7\u522b\u5927\u6a21\u578b\u65f6&#xff0c;**QLoRA \u5206\u9875\u4f18\u5316\u5668&#xff08;Paged Optimizers&#xff09;**\u88ab\u8a89\u4e3a\u7a77\u4eba\u7b97\u529b\u7684\u6551\u4e16\u4e3b\u3002\u901a\u8fc7 bitsandbytes \u63d0\u4f9b\u7684\u5206\u9875\u673a\u5236&#xff0c;\u5f53\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6fc0\u6d3b\u503c\u6216\u68af\u5ea6\u53d1\u751f\u77ac\u65f6\u5c16\u523a\u5bfc\u81f4\u663e\u5b58\u5373\u5c06\u6ea2\u51fa&#xff08;OOM&#xff09;\u65f6&#xff0c;\u5e95\u5c42\u9a71\u52a8\u4f1a\u81ea\u52a8\u5c06\u4f18\u5316\u5668\u72b6\u6001\u9875&#xff08;Optim\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/115055.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-10T17:57:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261010175701-6aca7c6ddfa05.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/115055.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/115055.html\",\"name\":\"Paged Optimizers \u663e\u5b58\u6362\u5165\u5ef6\u8fdf\u6cbb\u7406\uff1aQLoRA \u8bad\u7ec3\u541e\u5410\u8c03\u4f18\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-10T17:57:08+00:00\",\"dateModified\":\"2026-10-10T17:57:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/115055.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/115055.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/115055.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Paged Optimizers \u663e\u5b58\u6362\u5165\u5ef6\u8fdf\u6cbb\u7406\uff1aQLoRA \u8bad\u7ec3\u541e\u5410\u8c03\u4f18\u5b9e\u6218\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Paged Optimizers \u663e\u5b58\u6362\u5165\u5ef6\u8fdf\u6cbb\u7406\uff1aQLoRA \u8bad\u7ec3\u541e\u5410\u8c03\u4f18\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/115055.html","og_locale":"zh_CN","og_type":"article","og_title":"Paged Optimizers \u663e\u5b58\u6362\u5165\u5ef6\u8fdf\u6cbb\u7406\uff1aQLoRA \u8bad\u7ec3\u541e\u5410\u8c03\u4f18\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5728\u6d88\u8d39\u7ea7\u5355\u5361&#xff08;\u5982 RTX 4090 24GB&#xff09;\u6216\u5355\u5f20 A100 \u4e0a\u5fae\u8c03 70B \u7ea7\u522b\u5927\u6a21\u578b\u65f6&#xff0c;**QLoRA \u5206\u9875\u4f18\u5316\u5668&#xff08;Paged Optimizers&#xff09;**\u88ab\u8a89\u4e3a\u7a77\u4eba\u7b97\u529b\u7684\u6551\u4e16\u4e3b\u3002\u901a\u8fc7 bitsandbytes \u63d0\u4f9b\u7684\u5206\u9875\u673a\u5236&#xff0c;\u5f53\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6fc0\u6d3b\u503c\u6216\u68af\u5ea6\u53d1\u751f\u77ac\u65f6\u5c16\u523a\u5bfc\u81f4\u663e\u5b58\u5373\u5c06\u6ea2\u51fa&#xff08;OOM&#xff09;\u65f6&#xff0c;\u5e95\u5c42\u9a71\u52a8\u4f1a\u81ea\u52a8\u5c06\u4f18\u5316\u5668\u72b6\u6001\u9875&#xff08;Optim","og_url":"https:\/\/www.wsisp.com\/helps\/115055.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-10T17:57:08+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261010175701-6aca7c6ddfa05.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/115055.html","url":"https:\/\/www.wsisp.com\/helps\/115055.html","name":"Paged Optimizers \u663e\u5b58\u6362\u5165\u5ef6\u8fdf\u6cbb\u7406\uff1aQLoRA \u8bad\u7ec3\u541e\u5410\u8c03\u4f18\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-10T17:57:08+00:00","dateModified":"2026-10-10T17:57:08+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/115055.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/115055.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/115055.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Paged Optimizers \u663e\u5b58\u6362\u5165\u5ef6\u8fdf\u6cbb\u7406\uff1aQLoRA \u8bad\u7ec3\u541e\u5410\u8c03\u4f18\u5b9e\u6218"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/115055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=115055"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/115055\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/115054"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=115055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=115055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=115055"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=115055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}