MCPcopy Create free account
hub / github.com/InternLM/InternLM-XComposer / auto_configure_device_map

Function auto_configure_device_map

example_code/utils.py:6–35  ·  view source on GitHub ↗
(num_gpus)

Source from the content-addressed store, hash-verified

4from transformers import StoppingCriteria, StoppingCriteriaList
5
6def auto_configure_device_map(num_gpus):
7 # visual_encoder 算4层
8 # internlm_model.model.embed_tokens 占用1层
9 # norm 和 lm_head 占用1层
10 # transformer.layers 占用 32 层
11 # 总共34层分配到num_gpus张卡上
12 num_trans_layers = 32
13 per_gpu_layers = 38 / num_gpus
14
15 device_map = {
16 'vit': 0,
17 'vision_proj': 0,
18 'model.tok_embeddings': 0,
19 'plora_glb_GN': 0,
20 'plora_sub_GN': 0,
21 'model.norm': num_gpus - 1,
22 'output': num_gpus - 1,
23 }
24
25 used = 3
26 gpu_target = 0
27 for i in range(num_trans_layers):
28 if used >= per_gpu_layers:
29 gpu_target += 1
30 used = 0
31 assert gpu_target < num_gpus
32 device_map[f'model.layers.{i}'] = gpu_target
33 used += 1
34
35 return device_map
36
37class StoppingCriteriaSub(StoppingCriteria):
38

Callers 1

example_chat.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected