Commit 1eb4396
Fix Neuron engine for SDK 2.28+ and add Trainium (trn2) support (#659)
* Fix Neuron engine compatibility with optimum >= 2.0 and Neuron SDK 2.28
- Handle removal of optimum.bettertransformer in optimum >= 2.0 by wrapping
the import in try/except (acceleration.py)
- Include token_type_ids in Neuron tokenizer output to match compiled model
expectations (neuron.py)
- Update Dockerfile.neuron to remove pinned SDK versions
- Rewrite README.md with tested instructions for AWS DLAMI setup
Tested on inf2.xlarge with Neuron SDK 2.28, optimum-neuron 0.4.3 and 0.4.5.
Performance: ~210 embeddings/sec throughput, ~25ms latency (bge-small-en-v1.5).
* Add CHECK_OPTIMUM guard and cross-instance benchmarks
- Fix NameError when BetterTransformerManager is not available in
check_if_bettertransformer_possible() (affects both torch and neuron
engines on optimum >= 2.0)
- Update README with benchmark results across g5, inf2, trn2 instances
* Use data parallelism instead of tensor parallelism for Neuron
Compile models for a single NeuronCore (num_cores=1) instead of
sharding across all cores. This gives 5% better single-core
performance and enables linear scaling via multiple processes.
With 2 processes on inf2.xlarge (2 cores):
- Before (tensor parallel): 206 emb/s
- After (data parallel): 425 emb/s (+106%)
Update README with multi-process deployment instructions and
revised benchmark results.
* Add trn2.3xlarge benchmarks and data parallelism examples to Neuron docs
- Add trn2.3xlarge (4 NeuronCores) benchmark results: 19ms latency, 753 emb/s
- Add trn2 data parallelism example (4 processes on 4 cores)
- Restructure throughput table to show scaling across instance types
- Note: trn2 has ~30% lower per-core latency than inf2
* Address code review feedback: fix BetterTransformer guard, add NEURON_NUM_CORES env var
- acceleration.py: Use globals() check instead of CHECK_OPTIMUM.is_available
to correctly detect when bettertransformer import failed (mark_dirty does
not invalidate the cached is_available property)
- neuron.py: Add NEURON_NUM_CORES env var (default 1) so large models can
opt in to tensor parallelism without source changes
- neuron.py: Remove dead get_nc_count() function and unused imports
- Dockerfile: Merge RUN layers, add --no-cache-dir, add tested version comment
- README: Clean up redundant text in throughput table
---------
Co-authored-by: Ubuntu <ubuntu@ip-172-31-42-254.sa-east-1.compute.internal>1 parent 12defd7 commit 1eb4396
4 files changed
Lines changed: 171 additions & 83 deletions
File tree
- infra/aws_neuron
- libs/infinity_emb/infinity_emb/transformer
- embedder
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
3 | 9 | | |
4 | 10 | | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
8 | | - | |
| 14 | + | |
9 | 15 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | | - | |
17 | | - | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
| 25 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 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 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
10 | 118 | | |
11 | | - | |
12 | 119 | | |
13 | 120 | | |
14 | 121 | | |
15 | | - | |
| 122 | + | |
16 | 123 | | |
17 | 124 | | |
18 | | - | |
| 125 | + | |
19 | 126 | | |
20 | 127 | | |
21 | | - | |
| 128 | + | |
| 129 | + | |
22 | 130 | | |
23 | 131 | | |
24 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
25 | 135 | | |
26 | | - | |
27 | | - | |
28 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
29 | 143 | | |
30 | | - | |
31 | 144 | | |
32 | 145 | | |
33 | 146 | | |
| |||
45 | 158 | | |
46 | 159 | | |
47 | 160 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 161 | + | |
52 | 162 | | |
53 | 163 | | |
54 | 164 | | |
| |||
61 | 171 | | |
62 | 172 | | |
63 | 173 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 174 | + | |
68 | 175 | | |
69 | 176 | | |
70 | 177 | | |
71 | | - | |
72 | | - | |
73 | | - | |
| 178 | + | |
74 | 179 | | |
75 | 180 | | |
76 | 181 | | |
77 | 182 | | |
78 | | - | |
| 183 | + | |
79 | 184 | | |
80 | 185 | | |
81 | 186 | | |
82 | 187 | | |
83 | 188 | | |
84 | 189 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| |||
Lines changed: 16 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
15 | 24 | | |
16 | 25 | | |
17 | 26 | | |
| |||
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
40 | 52 | | |
41 | 53 | | |
42 | 54 | | |
| |||
Lines changed: 8 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 5 | + | |
9 | 6 | | |
10 | 7 | | |
11 | 8 | | |
| |||
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | 30 | | |
50 | 31 | | |
51 | 32 | | |
| |||
97 | 78 | | |
98 | 79 | | |
99 | 80 | | |
100 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
101 | 88 | | |
102 | 89 | | |
103 | 90 | | |
| |||
124 | 111 | | |
125 | 112 | | |
126 | 113 | | |
127 | | - | |
128 | 114 | | |
129 | 115 | | |
130 | 116 | | |
| |||
0 commit comments