MCPcopy Create free account
hub / github.com/Vahe1994/AQLM / dispatch_quantized_model

Function dispatch_quantized_model

src/modelutils.py:33–45  ·  view source on GitHub ↗
(model)

Source from the content-addressed store, hash-verified

31
32
33def dispatch_quantized_model(model):
34 num_devices = torch.cuda.device_count()
35 device_map = {"model.embed_tokens": 0, "model.norm": num_devices - 1, "lm_head": 0}
36 num_layers = len(get_layers(model))
37 layers_per_device = math.ceil(num_layers / num_devices)
38 for layer_id in range(num_layers):
39 device_id = layer_id // layers_per_device
40 device_map[f"model.layers.{layer_id}"] = device_id
41 model = dispatch_model(model, device_map)
42 # for some reason dispatch doesn't put this modules on needed device
43 model.model.embed_tokens = model.model.embed_tokens.to("cuda:0")
44 model.lm_head = model.lm_head.to("cuda:0")
45 return model
46
47
48def get_model(

Callers 1

get_modelFunction · 0.85

Calls 1

get_layersFunction · 0.85

Tested by

no test coverage detected