You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This implementation includes critical fixes for Granite's custom scaling:
57
+
58
+
1.**Attention Multiplier Fix**: The `prep_qkv_tensors` method in `NeuronGraniteAttention` applies a correction factor to Q tensors to convert from the standard `1/√head_dim` scaling to Granite's `attention_multiplier`.
59
+
60
+
2.**Embedding Multiplier**: Applied in `get_model_output` after embedding lookup (not to weights, to handle tied embeddings correctly).
61
+
62
+
3.**Logits Scaling**: Applied via `ScaledColumnParallelLinear` which divides output by `logits_scaling`.
63
+
64
+
4.**Residual Multiplier**: Applied in `NeuronGraniteDecoderLayer` to scale residual connections.
65
+
43
66
## Usage
44
67
45
68
```python
46
-
from transformers import AutoTokenizer, GenerationConfig
69
+
import torch
70
+
from transformers import AutoTokenizer
47
71
from neuronx_distributed_inference.models.config import NeuronConfig
48
72
from neuronx_distributed_inference.utils.hf_adapter import load_pretrained_config
49
73
50
74
# Import model classes from src
51
-
from src.modeling_granite_3_1_8b_instructimportNeurongranite318binstructForCausalLM, granite318binstructInferenceConfig
75
+
from src.modeling_graniteimportNeuronGraniteForCausalLM, GraniteInferenceConfig
52
76
53
77
model_path ="/path/to/granite-3.1-8b-instruct/"
54
78
compiled_model_path ="/path/to/compiled/"
@@ -61,18 +85,19 @@ neuron_config = NeuronConfig(
61
85
torch_dtype=torch.bfloat16,
62
86
)
63
87
64
-
config =granite318binstructInferenceConfig(
88
+
config =GraniteInferenceConfig(
65
89
neuron_config,
66
90
load_config=load_pretrained_config(model_path),
67
91
)
68
92
69
93
# Compile and load
70
-
model =Neurongranite318binstructForCausalLM(model_path, config)
94
+
model =NeuronGraniteForCausalLM(model_path, config)
0 commit comments