SpatialLM icon indicating copy to clipboard operation
SpatialLM copied to clipboard

训练,3块显卡总显存90g不够用,显存爆了。如何能控制显存占用

Open kaihekaihe opened this issue 1 year ago • 4 comments

使用了0,2,3显卡。Thu Oct 9 18:10:24 2025 +-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 550.144.03 Driver Version: 550.144.03 CUDA Version: 12.4 | |-----------------------------------------+------------------------+----------------------+ | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |=========================================+========================+======================| | 0 NVIDIA A100-PCIE-40GB Off | 00000000:31:00.0 Off | 0 | | N/A 36C P0 37W / 250W | 5245MiB / 40960MiB | 0% Default | | | | Disabled | +-----------------------------------------+------------------------+----------------------+ | 1 NVIDIA A100-PCIE-40GB Off | 00000000:4B:00.0 Off | 0 | | N/A 33C P0 35W / 250W | 28174MiB / 40960MiB | 0% Default | | | | Disabled | +-----------------------------------------+------------------------+----------------------+ | 2 NVIDIA A100-PCIE-40GB Off | 00000000:B1:00.0 Off | 0 | | N/A 35C P0 33W / 250W | 4MiB / 40960MiB | 0% Default | | | | Disabled | +-----------------------------------------+------------------------+----------------------+ | 3 NVIDIA A100-PCIE-40GB Off | 00000000:CA:00.0 Off | 0 | | N/A 38C P0 38W / 250W | 4MiB / 40960MiB | 0% Default | | | | Disabled |

(spatiallm) root@1f57cbdb5f75:/SpatialLM# PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True,garbage_collection_threshold:0.3 torchrun --nproc_per_node=3 /SpatialLM/spatiallm/tuner/trainer.py configs/spatiallm_sft.yaml W1009 10:03:17.758000 140128054925120 torch/distributed/run.py:779] W1009 10:03:17.758000 140128054925120 torch/distributed/run.py:779] ***************************************** W1009 10:03:17.758000 140128054925120 torch/distributed/run.py:779] Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed. W1009 10:03:17.758000 140128054925120 torch/distributed/run.py:779] ***************************************** [W1009 10:03:23.642510845 CUDAAllocatorConfig.h:28] Warning: expandable_segments not supported on this platform (function operator()) [WARNING|2025-10-09 10:03:23] spatiallm.tuner.hparams.parser:148 >> We recommend enable mixed precision training. [INFO|2025-10-09 10:03:23] spatiallm.tuner.hparams.parser:232 >> Process rank: 0, world size: 3, device: cuda:0, distributed training: True, compute dtype: None [INFO|tokenization_utils_base.py:2209] 2025-10-09 10:03:23,426 >> loading file vocab.json [INFO|tokenization_utils_base.py:2209] 2025-10-09 10:03:23,426 >> loading file merges.txt [INFO|tokenization_utils_base.py:2209] 2025-10-09 10:03:23,426 >> loading file tokenizer.json [INFO|tokenization_utils_base.py:2209] 2025-10-09 10:03:23,426 >> loading file added_tokens.json [INFO|tokenization_utils_base.py:2209] 2025-10-09 10:03:23,426 >> loading file special_tokens_map.json [INFO|tokenization_utils_base.py:2209] 2025-10-09 10:03:23,426 >> loading file tokenizer_config.json [W1009 10:03:23.791125249 CUDAAllocatorConfig.h:28] Warning: expandable_segments not supported on this platform (function operator()) [W1009 10:03:23.805956410 CUDAAllocatorConfig.h:28] Warning: expandable_segments not supported on this platform (function operator()) [INFO|tokenization_utils_base.py:2475] 2025-10-09 10:03:23,818 >> Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained. [INFO|2025-10-09 10:03:23] spatiallm.tuner.data.template:143 >> Add <|im_end|> to stop words. [WARNING|2025-10-09 10:03:23] spatiallm.tuner.data.loader:148 >> Loading dataset from disk will ignore other data arguments. [INFO|2025-10-09 10:03:23] spatiallm.tuner.data.loader:143 >> Loaded preprocessed dataset from saves/arkitscenes. [INFO|configuration_utils.py:677] 2025-10-09 10:03:23,827 >> loading configuration file manycore-research/SpatialLM1.1-Qwen-0.5B/config.json [INFO|configuration_utils.py:746] 2025-10-09 10:03:23,828 >> Model config SpatialLMQwenConfig { "_name_or_path": "manycore-research/SpatialLM1.1-Qwen-0.5B", "architectures": [ "SpatialLMQwenForCausalLM" ], "attention_dropout": 0.0, "bos_token_id": 151643, "eos_token_id": 151645, "hidden_act": "silu", "hidden_size": 896, "initializer_range": 0.02, "intermediate_size": 4864, "max_position_embeddings": 32768, "max_window_layers": 21, "model_type": "spatiallm_qwen", "num_attention_heads": 14, "num_hidden_layers": 24, "num_key_value_heads": 2, "point_backbone": "sonata", "point_config": { "enc_channels": [ 48, 96, 192, 384, 512 ], "enc_depths": [ 3, 3, 3, 12, 3 ], "enc_mode": true, "enc_num_head": [ 3, 6, 12, 24, 32 ], "enc_patch_size": [ 1024, 1024, 1024, 1024, 1024 ], "in_channels": 6, "mask_token": true, "mlp_ratio": 4, "num_bins": 1280, "order": [ "z", "z-trans", "hilbert", "hilbert-trans" ], "stride": [ 2, 2, 2, 2 ] }, "point_end_token_id": 151653, "point_start_token_id": 151652, "point_token_id": 151654, "projector": "mlp", "rms_norm_eps": 1e-06, "rope_scaling": null, "rope_theta": 1000000.0, "sliding_window": null, "tie_word_embeddings": true, "torch_dtype": "float32", "transformers_version": "4.46.1", "use_cache": false, "use_sliding_window": false, "vocab_size": 151936 }

[INFO|modeling_utils.py:3934] 2025-10-09 10:03:23,853 >> loading weights file manycore-research/SpatialLM1.1-Qwen-0.5B/model.safetensors [INFO|configuration_utils.py:1096] 2025-10-09 10:03:23,880 >> Generate config GenerationConfig { "bos_token_id": 151643, "eos_token_id": 151645, "use_cache": false }

[INFO|2025-10-09 10:03:23] spatiallm.tuner.hparams.parser:232 >> Process rank: 1, world size: 3, device: cuda:1, distributed training: True, compute dtype: None [INFO|2025-10-09 10:03:23] spatiallm.tuner.hparams.parser:232 >> Process rank: 2, world size: 3, device: cuda:2, distributed training: True, compute dtype: None[INFO|modeling_utils.py:4800] 2025-10-09 10:03:30,131 >> All model checkpoint weights were used when initializing SpatialLMQwenForCausalLM.

[INFO|modeling_utils.py:4808] 2025-10-09 10:03:30,131 >> All the weights of SpatialLMQwenForCausalLM were initialized from the model checkpoint at manycore-research/SpatialLM1.1-Qwen-0.5B. If your task is similar to the task the model of the checkpoint was trained on, you can already use SpatialLMQwenForCausalLM for predictions without further training. [INFO|configuration_utils.py:1049] 2025-10-09 10:03:30,137 >> loading configuration file manycore-research/SpatialLM1.1-Qwen-0.5B/generation_config.json [INFO|configuration_utils.py:1096] 2025-10-09 10:03:30,137 >> Generate config GenerationConfig { "bos_token_id": 151643, "eos_token_id": 151645 }

[INFO|2025-10-09 10:03:30] spatiallm.tuner.network.checkpointing:143 >> Gradient checkpointing enabled. [INFO|2025-10-09 10:03:30] spatiallm.tuner.framework.adapter:143 >> Upcasting trainable params to float32. [INFO|2025-10-09 10:03:30] spatiallm.tuner.framework.adapter:143 >> Fine-tuning method: Full [INFO|2025-10-09 10:03:30] spatiallm.tuner.framework.loader:143 >> trainable params: 603,511,168 || all params: 603,511,168 || trainable%: 100.0000 [INFO|trainer.py:2313] 2025-10-09 10:03:32,360 >> ***** Running training ***** [INFO|trainer.py:2314] 2025-10-09 10:03:32,360 >> Num examples = 4,497 [INFO|trainer.py:2315] 2025-10-09 10:03:32,360 >> Num Epochs = 10 [INFO|trainer.py:2316] 2025-10-09 10:03:32,360 >> Instantaneous batch size per device = 1 [INFO|trainer.py:2319] 2025-10-09 10:03:32,360 >> Total train batch size (w. parallel, distributed & accumulation) = 3 [INFO|trainer.py:2320] 2025-10-09 10:03:32,360 >> Gradient Accumulation steps = 1 [INFO|trainer.py:2321] 2025-10-09 10:03:32,360 >> Total optimization steps = 14,990 [INFO|trainer.py:2322] 2025-10-09 10:03:32,363 >> Number of trainable parameters = 603,511,168 [INFO|integration_utils.py:812] 2025-10-09 10:03:32,466 >> Automatic Weights & Biases logging enabled, to disable set os.environ["WANDB_DISABLED"] = "true" wandb: WARNING The run_name is currently set to the same value as TrainingArguments.output_dir. If this was not intended, please specify a different run name by setting the TrainingArguments.run_name parameter. wandb: (1) Create a W&B account wandb: (2) Use an existing W&B account wandb: (3) Don't visualize my results wandb: Enter your choice: 2 wandb: You chose 'Use an existing W&B account' wandb: Paste an API key from your profile and hit enter, or press ctrl+c to quit: wandb: Tracking run with wandb version 0.22.2 wandb: Run data is saved locally in /SpatialLM/wandb/run-20251009_100355-w0vofbxi wandb: Run wandb offline to turn off syncing. wandb: Syncing run saves 0%| | 0/14990 [00:00<?, ?it/s]/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/utils/checkpoint.py:295: FutureWarning: torch.cpu.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cpu', args...) instead. with torch.enable_grad(), device_autocast_ctx, torch.cpu.amp.autocast(**ctx.cpu_autocast_kwargs): # type: ignore[attr-defined] /opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/utils/checkpoint.py:295: FutureWarning: torch.cpu.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cpu', args...) instead. with torch.enable_grad(), device_autocast_ctx, torch.cpu.amp.autocast(**ctx.cpu_autocast_kwargs): # type: ignore[attr-defined] /opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/utils/checkpoint.py:295: FutureWarning: torch.cpu.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cpu', args...) instead. with torch.enable_grad(), device_autocast_ctx, torch.cpu.amp.autocast(**ctx.cpu_autocast_kwargs): # type: ignore[attr-defined] 0%| | 3/14990 [00:28<27:37:55, 6.64s/it]Traceback (most recent call last): File "/SpatialLM/spatiallm/tuner/trainer.py", line 217, in run_exp() File "/SpatialLM/spatiallm/tuner/trainer.py", line 213, in run_exp _training_function(config={"args": args}) File "/SpatialLM/spatiallm/tuner/trainer.py", line 192, in _training_function run_sft( File "/SpatialLM/spatiallm/tuner/trainer.py", line 161, in run_sft train_result = trainer.train( ^^^^^^^^^^^^^^ File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/transformers/trainer.py", line 2122, in train return inner_training_loop( ^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/transformers/trainer.py", line 2474, in _inner_training_loop tr_loss_step = self.training_step(model, inputs, num_items_in_batch) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/transformers/trainer.py", line 3606, in training_step self.accelerator.backward(loss, **kwargs) File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/accelerate/accelerator.py", line 2473, in backward loss.backward(**kwargs) File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/_tensor.py", line 521, in backward torch.autograd.backward( File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/autograd/init.py", line 289, in backward _engine_run_backward( File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/autograd/graph.py", line 769, in _engine_run_backward return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 1.93 GiB. GPU 0 has a total capacity of 39.38 GiB of which 278.69 MiB is free. Process 323512 has 480.00 MiB memory in use. Process 323522 has 480.00 MiB memory in use. Process 449836 has 4.16 GiB memory in use. Process 1607263 has 33.98 GiB memory in use. Of the allocated memory 33.18 GiB is allocated by PyTorch, and 163.50 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables) [rank0]: Traceback (most recent call last): [rank0]: File "/SpatialLM/spatiallm/tuner/trainer.py", line 217, in [rank0]: run_exp() [rank0]: File "/SpatialLM/spatiallm/tuner/trainer.py", line 213, in run_exp [rank0]: _training_function(config={"args": args}) [rank0]: File "/SpatialLM/spatiallm/tuner/trainer.py", line 192, in _training_function [rank0]: run_sft( [rank0]: File "/SpatialLM/spatiallm/tuner/trainer.py", line 161, in run_sft [rank0]: train_result = trainer.train( [rank0]: ^^^^^^^^^^^^^^ [rank0]: File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/transformers/trainer.py", line 2122, in train [rank0]: return inner_training_loop( [rank0]: ^^^^^^^^^^^^^^^^^^^^ [rank0]: File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/transformers/trainer.py", line 2474, in _inner_training_loop [rank0]: tr_loss_step = self.training_step(model, inputs, num_items_in_batch) [rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank0]: File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/transformers/trainer.py", line 3606, in training_step [rank0]: self.accelerator.backward(loss, **kwargs) [rank0]: File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/accelerate/accelerator.py", line 2473, in backward [rank0]: loss.backward(**kwargs) [rank0]: File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/_tensor.py", line 521, in backward [rank0]: torch.autograd.backward( [rank0]: File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/autograd/init.py", line 289, in backward [rank0]: _engine_run_backward( [rank0]: File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/autograd/graph.py", line 769, in _engine_run_backward [rank0]: return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass [rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank0]: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 1.93 GiB. GPU 0 has a total capacity of 39.38 GiB of which 278.69 MiB is free. Process 323512 has 480.00 MiB memory in use. Process 323522 has 480.00 MiB memory in use. Process 449836 has 4.16 GiB memory in use. Process 1607263 has 33.98 GiB memory in use. Of the allocated memory 33.18 GiB is allocated by PyTorch, and 163.50 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables) wandb: wandb: 🚀 View run saves at: wandb: Find logs at: wandb/run-20251009_100355-w0vofbxi/logs W1009 10:04:26.956000 140128054925120 torch/distributed/elastic/multiprocessing/api.py:858] Sending process 3731 closing signal SIGTERM W1009 10:04:26.957000 140128054925120 torch/distributed/elastic/multiprocessing/api.py:858] Sending process 3732 closing signal SIGTERM E1009 10:04:27.435000 140128054925120 torch/distributed/elastic/multiprocessing/api.py:833] failed (exitcode: 1) local_rank: 0 (pid: 3730) of binary: /opt/conda/envs/spatiallm/bin/python3.11 Traceback (most recent call last): File "/opt/conda/envs/spatiallm/bin/torchrun", line 7, in sys.exit(main()) ^^^^^^ File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/distributed/elastic/multiprocessing/errors/init.py", line 348, in wrapper return f(*args, **kwargs) ^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/distributed/run.py", line 901, in main run(args) File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/distributed/run.py", line 892, in run elastic_launch( File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 133, in call return launch_agent(self._config, self._entrypoint, list(args)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/spatiallm/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 264, in launch_agent raise ChildFailedError( torch.distributed.elastic.multiprocessing.errors.ChildFailedError:

/SpatialLM/spatiallm/tuner/trainer.py FAILED

Failures: <NO_OTHER_FAILURES>

Root Cause (first observed failure): [0]: time : 2025-10-09_10:04:26 host : 1f57cbdb5f75 rank : 0 (local_rank: 0) exitcode : 1 (pid: 3730) error_file: <N/A> traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html

kaihekaihe avatar Oct 09 '25 10:10 kaihekaihe

Hi,full finetune的版本需要单卡现存是60GB,如果显存不够的话,可能可以试试用pure bf16,也可以试试deepspeed,这些techinique。显存的需求和点云的分辨率,点云的大小这些也都有关系,可能需要你选择一个适合的setting哈。

SamMaoYS avatar Oct 14 '25 04:10 SamMaoYS

deepspeed ZERo3和sponv有兼容性问题,降到ZERo2还在试,有没有已经work的deepspeed脚本可以借鉴一下

kaihekaihe avatar Oct 14 '25 11:10 kaihekaihe

是的,你可以借鉴一下llama factory提供的deepspeed设置样例. 我们没有在release的代码中测试过deepspeed的训练,还是需要辛苦你测试一下。谢谢!

SamMaoYS avatar Oct 30 '25 06:10 SamMaoYS

What is the requirement of GPU of training for this project?

ihuchao avatar Mar 31 '26 02:03 ihuchao