Update config.json
#160
by
jana0010
- opened
- config.json +52 -70
config.json
CHANGED
@@ -1,70 +1,52 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
"mscale": 1.0,
|
54 |
-
"mscale_all_dim": 1.0,
|
55 |
-
"original_max_position_embeddings": 4096,
|
56 |
-
"type": "yarn"
|
57 |
-
},
|
58 |
-
"rope_theta": 10000,
|
59 |
-
"routed_scaling_factor": 2.5,
|
60 |
-
"scoring_func": "sigmoid",
|
61 |
-
"seq_aux": true,
|
62 |
-
"tie_word_embeddings": false,
|
63 |
-
"topk_group": 4,
|
64 |
-
"topk_method": "noaux_tc",
|
65 |
-
"torch_dtype": "bfloat16",
|
66 |
-
"transformers_version": "4.46.3",
|
67 |
-
"use_cache": true,
|
68 |
-
"v_head_dim": 128,
|
69 |
-
"vocab_size": 129280
|
70 |
-
}
|
|
|
1 |
+
def load_model_with_quantization_fallback(
|
2 |
+
model_name: str = "deepseek-ai/DeepSeek-R1",
|
3 |
+
trust_remote_code: bool = True,
|
4 |
+
device_map: Optional[Union[str, Dict[str, Any]]] = "auto",
|
5 |
+
**kwargs
|
6 |
+
) -> Tuple[PreTrainedModel, PreTrainedTokenizer]:
|
7 |
+
|
8 |
+
try:
|
9 |
+
model = AutoModel.from_pretrained(
|
10 |
+
model_name,
|
11 |
+
trust_remote_code=trust_remote_code,
|
12 |
+
device_map=device_map,
|
13 |
+
**kwargs
|
14 |
+
)
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
16 |
+
logger.info("Model loaded successfully with original configuration")
|
17 |
+
return model, tokenizer
|
18 |
+
except ValueError as e:
|
19 |
+
if "Unknown quantization type" in str(e):
|
20 |
+
logger.warning(
|
21 |
+
"Quantization type not supported directly. "
|
22 |
+
"Attempting to load without quantization..."
|
23 |
+
)
|
24 |
+
|
25 |
+
config = AutoConfig.from_pretrained(
|
26 |
+
model_name,
|
27 |
+
trust_remote_code=trust_remote_code
|
28 |
+
)
|
29 |
+
if hasattr(config, "quantization_config"):
|
30 |
+
delattr(config, "quantization_config")
|
31 |
+
|
32 |
+
try:
|
33 |
+
model = AutoModel.from_pretrained(
|
34 |
+
model_name,
|
35 |
+
config=config,
|
36 |
+
trust_remote_code=trust_remote_code,
|
37 |
+
device_map=device_map,
|
38 |
+
**kwargs
|
39 |
+
)
|
40 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
41 |
+
model_name,
|
42 |
+
trust_remote_code=trust_remote_code
|
43 |
+
)
|
44 |
+
logger.info("Model loaded successfully without quantization")
|
45 |
+
return model, tokenizer
|
46 |
+
|
47 |
+
except Exception as inner_e:
|
48 |
+
logger.error(f"Failed to load model without quantization: {str(inner_e)}")
|
49 |
+
raise
|
50 |
+
else:
|
51 |
+
logger.error(f"Unexpected error during model loading: {str(e)}")
|
52 |
+
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|