Lecture 04-2 · Pruning and Sparsity IIالمحاضرة 04-2 · التقليم والتناثر II
Sparse convolution for point clouds
الالتفاف المتناثر لسحب النقاط (point clouds)
P1 MUSTA LiDAR scan is almost all empty air. Ordinary convolution smears every point into its neighbours until the emptiness is gone. Submanifold sparse convolution computes outputs only where inputs exist, and the whole layer becomes a short list of (In, Out, Wgt) tuples you can write by hand.
مسح LiDAR هو هواء فارغ في معظمه. الـ convolution العادي يلطّخ كل نقطة على جيرانها حتى يختفي الفراغ. أما submanifold sparse convolution فيحسب المخرجات فقط حيث توجد مدخلات، فتصبح الطبقة كلها قائمة قصيرة من الثلاثيات (In, Out, Wgt) يمكنك كتابتها بيدك.
Expect: "how many active sites after L dense layers?", "build the map for this small grid", and "how many matmuls does the weight-stationary GPU version launch?". Get the offset sign convention right before you start.
توقّع: "كم موقعاً نشطاً بعد L طبقات كثيفة؟"، و"ابنِ map لهذه الشبكة الصغيرة"، و"كم matmul تطلق نسخة GPU من نوع weight-stationary؟". ثبّت اصطلاح إشارة الإزاحة قبل أن تبدأ.
How sparse is a point cloud?
ما مدى تناثر سحابة النقاط؟
Voxelize an outdoor LiDAR frame and fewer than 0.01 percent of cells hold a point. An ImageNet input is 100 percent dense, and about 50 percent nonzero after ReLU. Indoor scenes and single objects sit below 1 percent.
حوّل إطار LiDAR خارجياً إلى voxels فتجد أن أقل من 0.01% من الخلايا تحتوي نقطة. أما صورة ImageNet فكثافتها 100%، ونحو 50% غير صفري بعد ReLU. والمشاهد الداخلية والأجسام المفردة أقل من 1%.
This is activation sparsity, but its source is geometry: the zeros are the space between surfaces, so the nonzero pattern should never grow during computation.
هذه activation sparsity، لكن مصدرها الهندسة: الأصفار هي المسافة بين الأسطح، لذا يجب ألا يتمدد نمط القيم غير الصفرية أثناء الحساب.
The dilation problem
مشكلة التمدد (dilation)
A dense 3d convolution turns one active site into 3d after one layer and 5d after two: in general (2L + 1)d. In 3D that is 1, 27, 125. On the slide grid (4 x 5, active cells at (1,1), (2,2), (2,4), (3,3)), one dense 3 x 3 layer turns 4 of 20 cells into 17 of 20; a second layer fills all 20.
convolution كثيف بحجم 3d يحوّل موقعاً نشطاً واحداً إلى 3d بعد طبقة واحدة و5d بعد طبقتين، وعموماً (2L + 1)d. في الأبعاد الثلاثة: 1 ثم 27 ثم 125. وعلى شبكة الشريحة (4 x 5 بخلايا نشطة عند (1,1) و(2,2) و(2,4) و(3,3))، تحوّل طبقة 3 x 3 كثيفة واحدة 4 من 20 خلية إلى 17 من 20، وتملأ الطبقة الثانية الخلايا الـ 20 كلها.
Submanifold sparse convolution
الالتفاف المتناثر submanifold
Definition: an output site is computed if and only if the input site at the same coordinate is active (odd kernel, stride 1, same padding). So Pout = Pin, and a deep network stays as sparse as its first layer. It does not compute and mask; it never visits empty positions at all.
التعريف: يُحسب موقع الخرج إذا وفقط إذا كان موقع الدخل في نفس الإحداثي نشطاً (kernel فردي، stride 1، same padding). إذن Pout = Pin، وتبقى الشبكة العميقة متناثرة بقدر طبقتها الأولى. هو لا يحسب ثم يُقنّع، بل لا يزور المواقع الفارغة أصلاً.
The map and the update rule
الخريطة (map) وقاعدة التحديث
A 3 x 3 kernel is nine weight matrices W(dx,dy), each Cin x Cout, with dx, dy in {-1, 0, 1}. The layer is a list of maps (In, Out, Wgt). The deck's convention: input P sits at output Q shifted by the offset, P = Q + (dx, dy) in (row, column). For every entry:
kernel بحجم 3 x 3 هو تسع مصفوفات أوزان W(dx,dy)، كل منها Cin x Cout، حيث dx, dy من {-1, 0, 1}. الطبقة هي قائمة maps (In, Out, Wgt). واصطلاح الشرائح: الدخل P يقع عند الخرج Q مزاحاً بالإزاحة، أي P = Q + (dx, dy) بترتيب (صف، عمود). ولكل مدخل في القائمة:
f_out(Q) = f_out(Q) + f_in(P) x W_(dx,dy) one (1 x C_in)(C_in x C_out) product
كل مدخل في map هو ضرب متجه في مصفوفة واحد بحجم (1 x Cin)(Cin x Cout)، يُجمع في متجه الخرج.
Slide 95 follows P0 at (1,1). Conventionally P0 lands in nine output windows: nine entries, from (P0, Q0, W1,1) at the top-left to (P0, Q10, W-1,-1) at the bottom-right. Sparse: only outputs that are themselves inputs survive, P0's own cell (W0,0) and (2,2) where P1 sits (W-1,-1). 9 entries become 2.
الشريحة 95 تتتبّع P0 عند (1,1). في الطريقة التقليدية يقع P0 في تسع نوافذ خرج: تسعة مدخلات، من (P0, Q0, W1,1) أعلى اليسار إلى (P0, Q10, W-1,-1) أسفل اليمين. أما المتناثرة فلا يبقى إلا الخرج الذي هو نفسه دخل: خلية P0 نفسها (W0,0) و(2,2) حيث يقع P1 (W-1,-1). تسعة مدخلات تصبح اثنين.
Worked: build the map for slide 96
مثال محلول: ابنِ الخريطة للشريحة 96
5 x 5 grid, five points in row-major order: P0 (1,1), P1 (2,2), P2 (2,4), P3 (3,2), P4 (4,3). Outputs Qi sit at the same positions. For each pair within one step, the offset is (dx, dy) = P - Q.
شبكة 5 x 5 فيها خمس نقاط بترتيب الصفوف: P0 (1,1) وP1 (2,2) وP2 (2,4) وP3 (3,2) وP4 (4,3). المخرجات Qi في نفس المواقع. لكل زوج على بعد خطوة واحدة، الإزاحة هي (dx, dy) = P - Q.
centre entries (every point onto itself), W_0,0:
(P0,Q0) (P1,Q1) (P2,Q2) (P3,Q3) (P4,Q4) 5 entries
neighbour pairs (Chebyshev distance 1), both directions:
P0 (1,1) - P1 (2,2): (P0,Q1) dx,dy = (1,1)-(2,2) = (-1,-1)
(P1,Q0) dx,dy = (2,2)-(1,1) = ( 1, 1)
P1 (2,2) - P3 (3,2): (P1,Q3) = (-1, 0) (P3,Q1) = ( 1, 0)
P3 (3,2) - P4 (4,3): (P3,Q4) = (-1,-1) (P4,Q3) = ( 1, 1)
P2 (2,4): no neighbour, (2,2) is two columns away 6 entries
group by weight (one matmul each, weight-stationary)
W_-1,-1 : (P0,Q1) (P3,Q4) 2 rows
W_-1,0 : (P1,Q3) 1 row
W_0,0 : all five centre entries 5 rows
W_1,0 : (P3,Q1) 1 row
W_1,1 : (P1,Q0) (P4,Q3) 2 rows
other 4 offsets: empty, no launch
total 11 entries, 5 matmuls
Each offset and its mirror have equal map size (2 and 2, 1 and 1), because every neighbouring pair appears once in each direction.
لكل إزاحة ومعكوسها نفس حجم map (2 و2، و1 و1)، لأن كل زوج متجاور يظهر مرة في كل اتجاه.
Weight-stationary execution
التنفيذ بأسلوب weight-stationary
The GPU version on slide 96: for one offset, gather the input rows named by its entries into a buffer (for W-1,-1: P0 and P3, a 2 x Cin buffer), run one matmul with the Cin x Cout weight to get a 2 x Cout partial sum, then scatter-add the rows into Q1 and Q4: f1 += f0 x W-1,-1, f4 += f3 x W-1,-1. Repeat per offset: five matmuls with 2, 1, 5, 1, 2 rows.
نسخة GPU في الشريحة 96: لإزاحة واحدة، اجمع (gather) صفوف الدخل المذكورة في مدخلاتها في buffer (لـ W-1,-1: P0 وP3، أي buffer بحجم 2 x Cin)، ثم نفّذ matmul واحداً مع الوزن Cin x Cout لتحصل على partial sum بحجم 2 x Cout، ثم وزّع وأضف (scatter-add) الصفوف إلى Q1 وQ4: f1 += f0 x W-1,-1 وf4 += f3 x W-1,-1. كرّر لكل إزاحة: خمسة matmuls بعدد صفوف 2, 1, 5, 1, 2.
| Slide 87 grid (4 x 5, 4 points), Cin = Cout = 64شبكة الشريحة 87 (4 x 5، 4 نقاط)، Cin = Cout = 64 | Entriesالمُدخلات | MACsMACs |
|---|---|---|
| Fully dense 3 x 3 over all 20 outputsكثيف بالكامل 3 x 3 على كل المخرجات الـ 20 | 20 x 9 = 180 | 737,280 |
| Conventional, skipping zero inputsتقليدي، مع تخطي المدخلات الصفرية | 9 + 9 + 6 + 6 = 30 | 122,880 |
| Submanifold sparseمتناثر submanifold | 4 + 3 x 2 = 10 | 40,960 |
كل مدخل يكلّف 64 x 64 = 4,096 MACs. التقليدي مع تخطّي الأصفار يعطي 30 مدخلاً لأن النقطتين على الحافة لهما ست نوافذ فقط داخل الشبكة. والمتناثر يعطي 10: أربعة مراكز وثلاثة أزواج متجاورة في الاتجاهين.
Zero-skipping alone already cuts most of the work, but it still writes 17 outputs, so the next layer starts from 17 points. Only the submanifold row stays proportional to the number of points layer after layer.
تخطّي الأصفار وحده يزيل معظم العمل، لكنه ما زال يكتب 17 خرجاً، فتبدأ الطبقة التالية من 17 نقطة. الصف submanifold وحده يبقى متناسباً مع عدد النقاط طبقة بعد طبقة.
Three kinds of sparsity, do not mix them. Point-cloud sparsity (input geometry, below 0.01 percent dense, handled by sparse conv), ReLU activation sparsity (about 50 percent, EIE skips it), pruned weight sparsity (static, EIE or 2:4).
ثلاثة أنواع من sparsity، لا تخلط بينها. تناثر point cloud (هندسة الدخل، كثافة أقل من 0.01%، يعالجه sparse conv)، وتناثر التنشيطات من ReLU (نحو 50%، يتخطّاه EIE)، وتناثر الأوزان المقلّمة (ثابت، EIE أو 2:4).
Offset sign convention. The deck uses P = Q + (dx, dy), so (P0, Q0, W1,1) sends P0 to the output one row up and one column left. TorchSparse's paper writes q = p + δ, flipping every label. State your convention first.
اصطلاح إشارة الإزاحة. الشرائح تستخدم P = Q + (dx, dy)، فالمدخل (P0, Q0, W1,1) يرسل P0 إلى الخرج الأعلى بصف والأيسر بعمود. أما ورقة TorchSparse فتكتب q = p + δ، فتنقلب كل التسميات. اذكر اصطلاحك أولاً.
Two numberings of Q. On slide 95 the dense side numbers 17 dilated outputs (P0's cell is Q4), the sparse side numbers only the 4 survivors (the same cell is Q0).
ترقيمان مختلفان لـ Q. في الشريحة 95 يرقّم الجانب الكثيف 17 خرجاً متمدداً (خلية P0 هي Q4)، والجانب المتناثر يرقّم الأربعة الباقية فقط (نفس الخلية هي Q0).
A sparse set of dense MMAs, with rules defined by maps. Dense conv is a wet brush that bleeds; submanifold conv is a dry stamp that only re-inks the dots already there.
مجموعة متناثرة من عمليات MMA كثيفة، قواعدها تحددها maps. الـ conv الكثيف فرشاة مبللة تنزّ، وsubmanifold conv ختم جاف يعيد تحبير النقاط الموجودة فقط.
Check yourself
اختبر نفسك
A single active voxel passes through two dense 3 x 3 x 3 convolutions. How many active sites are there after the second layer?
voxel نشط واحد يمر عبر طبقتي convolution كثيفتين بحجم 3 x 3 x 3. كم موقعاً نشطاً بعد الطبقة الثانية؟
(2L + 1)d with L = 2, d = 3: 53 = 125. Option A is the 2D answer, B is one layer in 3D, C wrongly adds 27 + 27.
(2L + 1)d مع L = 2 وd = 3: 53 = 125. الخيار A إجابة البعدين، وB طبقة واحدة في ثلاثة أبعاد، وC يجمع 27 + 27 خطأً.
A 3 x 3 submanifold sparse convolution runs over the four active cells of the slide's 4 x 5 grid. How many output cells are computed?
submanifold sparse convolution بحجم 3 x 3 يعمل على الخلايا النشطة الأربع في شبكة الشريحة 4 x 5. كم خلية خرج تُحسب؟
Pout = Pin: four outputs. 17 is the dense dilated set, 20 the grid after a second dense layer, and 10 is the number of map entries, not outputs.
Pout = Pin: أربعة مخرجات. 17 هي المجموعة المتمددة الكثيفة، و20 الشبكة بعد طبقة كثيفة ثانية، و10 عدد مدخلات map لا عدد المخرجات.
With the deck's convention P = Q + (dx, dy), input P sits at (3,2) and the entry uses W1,0. Where is the output Q?
باصطلاح الشرائح P = Q + (dx, dy)، يقع الدخل P عند (3,2) والمدخل يستخدم W1,0. أين يقع الخرج Q؟
Q = P - (dx, dy) = (3,2) - (1,0) = (2,2). This is (P3, Q1, W1,0) on slide 96. Option B applies the opposite sign convention.
Q = P - (dx, dy) = (3,2) - (1,0) = (2,2). هذا هو (P3, Q1, W1,0) في الشريحة 96. الخيار B يطبّق الاصطلاح المعاكس للإشارة.
The slide 96 map has 11 entries over 9 possible offsets. How many matmuls does the weight-stationary GPU implementation launch?
map الشريحة 96 فيه 11 مدخلاً على 9 إزاحات ممكنة. كم matmul يطلق تنفيذ GPU من نوع weight-stationary؟
Entries sharing a weight are gathered into one buffer and multiplied together: W-1,-1, W-1,0, W0,0, W1,0, W1,1 with 2, 1, 5, 1, 2 rows. The other four offsets have no entries and no launch.
المدخلات التي تشترك في نفس الوزن تُجمع في buffer واحد وتُضرب معاً: W-1,-1 وW-1,0 وW0,0 وW1,0 وW1,1 بصفوف 2, 1, 5, 1, 2. الإزاحات الأربع الأخرى بلا مدخلات ولا إطلاق.
Which sparsity does submanifold sparse convolution exploit?
أي نوع من sparsity يستغله submanifold sparse convolution؟
The zeros are empty voxels between surfaces. The weights stay dense; the savings come from skipping empty positions and never creating new ones.
الأصفار هي voxels فارغة بين الأسطح. تبقى الأوزان كثيفة، والتوفير يأتي من تخطّي المواقع الفارغة وعدم إنشاء مواقع جديدة أبداً.