/
usr
/
local
/
lib
/
python3.6
/
site-packages
/
transformers
/
utils
/
/usr/local/lib/python3.6/site-packages/transformers/utils
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
doc.py
38836
0644
edit
dl
rm
dummy_detectron2_objects.py
391
0644
edit
dl
rm
dummy_flax_objects.py
24855
0644
edit
dl
rm
dummy_pt_objects.py
111443
0644
edit
dl
rm
dummy_pytorch_quantization_and_torch_objects.py
2476
0644
edit
dl
rm
dummy_scatter_objects.py
1138
0644
edit
dl
rm
dummy_sentencepiece_and_speech_objects.py
342
0644
edit
dl
rm
dummy_sentencepiece_and_tokenizers_objects.py
301
0644
edit
dl
rm
dummy_sentencepiece_objects.py
4371
0644
edit
dl
rm
dummy_speech_objects.py
315
0644
edit
dl
rm
dummy_tf_objects.py
50456
0644
edit
dl
rm
dummy_timm_and_vision_objects.py
903
0644
edit
dl
rm
dummy_timm_objects.py
805
0644
edit
dl
rm
dummy_tokenizers_objects.py
8173
0644
edit
dl
rm
dummy_vision_objects.py
3486
0644
edit
dl
rm
fx.py
23186
0644
edit
dl
rm
fx_transformations.py
12178
0644
edit
dl
rm
generic.py
9820
0644
edit
dl
rm
hp_naming.py
4971
0644
edit
dl
rm
hub.py
42932
0644
edit
dl
rm
import_utils.py
29288
0644
edit
dl
rm
logging.py
9516
0644
edit
dl
rm
model_parallel_utils.py
2276
0644
edit
dl
rm
notebook.py
14524
0644
edit
dl
rm
sentencepiece_model_pb2.py
39607
0644
edit
dl
rm
versions.py
4378
0644
edit
dl
rm
__init__.py
5055
0644
edit
dl
rm
Edit:
/usr/local/lib/python3.6/site-packages/transformers/utils/model_parallel_utils.py
(2276B)
# coding=utf-8 # Copyright 2020 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from math import ceil def assert_device_map(device_map, num_blocks): blocks = list(range(0, num_blocks)) device_map_blocks = [item for sublist in list(device_map.values()) for item in sublist] # Duplicate check duplicate_blocks = [] for i in device_map_blocks: if device_map_blocks.count(i) > 1 and i not in duplicate_blocks: duplicate_blocks.append(i) # Missing blocks missing_blocks = [i for i in blocks if i not in device_map_blocks] extra_blocks = [i for i in device_map_blocks if i not in blocks] if len(duplicate_blocks) != 0: raise ValueError( "Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device. These " "attention blocks were specified more than once: " + str(duplicate_blocks) ) if len(missing_blocks) != 0: raise ValueError( "There are attention blocks for this model that are not specified in the device_map. Add these attention " "blocks to a device on the device_map: " + str(missing_blocks) ) if len(extra_blocks) != 0: raise ValueError( "The device_map contains more attention blocks than this model has. Remove these from the device_map:" + str(extra_blocks) ) def get_device_map(n_layers, devices): """Returns a dictionary of layers distributed evenly across all devices.""" layers = list(range(n_layers)) n_blocks = int(ceil(n_layers / len(devices))) layers_list = list(layers[i : i + n_blocks] for i in range(0, n_layers, n_blocks)) return dict(zip(devices, layers_list))
Save
cmd:
run