Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supported transpose conv1/2d and added tests #83

Closed
wants to merge 76 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
e2f3e74
⚡️ added `Identity`. Renamed & exposed `SynConnType` to pb
KafCoppelia Mar 7, 2024
6a56132
✅ sync changes
KafCoppelia Mar 7, 2024
1890ee2
🐛 fixed the situation when there are no input nodes in the graph
KafCoppelia Mar 8, 2024
1dd83f0
🚚 renamed arguments due to paicorelib
KafCoppelia Mar 8, 2024
66db0c0
💬 updated comments
KafCoppelia Mar 8, 2024
2e36254
✅ refactored parameterized test data format
KafCoppelia Mar 8, 2024
68eca96
📝 updated README
KafCoppelia Mar 8, 2024
6ecb5d1
:rotating_light: auto fix by pre-commit hooks
pre-commit-ci[bot] Mar 8, 2024
b150145
Merge pull request #75 from PAICookers/frontend
KafCoppelia Mar 8, 2024
78ff5af
🐛 bugfix: added MAX_NESTED_LEVEL to implement parsing of nested struc…
KafCoppelia Mar 11, 2024
f7afe13
✅ added tests for parsing of nested structures
KafCoppelia Mar 11, 2024
6daa8e5
📝 updated building a nested network doc
KafCoppelia Mar 11, 2024
7ad9094
:rotating_light: auto fix by pre-commit hooks
pre-commit-ci[bot] Mar 11, 2024
526b45d
Merge pull request #76 from PAICookers/frontend
KafCoppelia Mar 11, 2024
7868e39
✨ implemented recursive search for all child nodes
KafCoppelia Mar 12, 2024
868702e
✅ added tests for recursive search for nodes & removed useless test o…
KafCoppelia Mar 12, 2024
0d646b4
✨ supported 2d convolution
KafCoppelia Mar 15, 2024
19f290f
✨ improved typing & libraries import
KafCoppelia Mar 15, 2024
9137787
🐛 bugfix: wrong shape of stateful variables in neurons when keep_shap…
KafCoppelia Mar 15, 2024
160ea3a
✅ added tests for 2d conv
KafCoppelia Mar 15, 2024
f7a2cf3
✅ sync changes
KafCoppelia Mar 15, 2024
e0e9717
📦 added an example for conv2d network
KafCoppelia Mar 15, 2024
3bb381e
📝 updated example1 of MNIST
KafCoppelia Mar 15, 2024
e7bc7b1
🙈 updated .gitignore
KafCoppelia Mar 15, 2024
bf38fe9
📝 updated TODO list
KafCoppelia Mar 15, 2024
8cb0305
🗑️ removed useless code
KafCoppelia Mar 15, 2024
b5cef77
📝 updated the guide
KafCoppelia Mar 15, 2024
cdfaaff
📝 updated toml & changelog
KafCoppelia Mar 15, 2024
6736dc2
:rotating_light: auto fix by pre-commit hooks
pre-commit-ci[bot] Mar 15, 2024
c401877
Merge pull request #77 from PAICookers/frontend
KafCoppelia Mar 15, 2024
2809451
✨ added Always1Neuron
KafCoppelia Mar 19, 2024
3a25fa5
🎨 updated typing & comments
KafCoppelia Mar 19, 2024
1499678
🔨 only supports deletion of synapses between two specified neurons
KafCoppelia Mar 19, 2024
4b4060d
✅ added tests & sync changes
KafCoppelia Mar 19, 2024
ac6fc32
📝 updated toml, todo & changelog
KafCoppelia Mar 19, 2024
3358b50
:rotating_light: auto fix by pre-commit hooks
pre-commit-ci[bot] Mar 19, 2024
f4a6721
Merge pull request #78 from PAICookers/frontend
KafCoppelia Mar 19, 2024
79afc93
✨ added latency encoder & simplified encoder classes
KafCoppelia Mar 20, 2024
f2c8e13
✅ added tests for latency encoder
KafCoppelia Mar 20, 2024
a021894
🎨 updated exceptions text
KafCoppelia Mar 20, 2024
fcef26e
📝 updated docs
KafCoppelia Mar 20, 2024
d87e3f1
✨ supported 1d convolution
KafCoppelia Mar 24, 2024
44349c1
✅ added tests for 1d conv
KafCoppelia Mar 24, 2024
231629c
🚚 renamed files
KafCoppelia Mar 24, 2024
1a090e8
📝 updated todo & changelog
KafCoppelia Mar 24, 2024
83f91ee
:rotating_light: auto fix by pre-commit hooks
pre-commit-ci[bot] Mar 24, 2024
cba5b1e
Merge pull request #79 from PAICookers/bugfix-1
KafCoppelia Mar 24, 2024
23b07ad
⬆️ bump numpy >= 1.24
KafCoppelia Mar 25, 2024
15cdb83
📝 updated TODO
KafCoppelia Mar 25, 2024
ec0cb1c
🐛 bugfix: wrong sum inputs of neuron
KafCoppelia Mar 26, 2024
2a80a76
:arrow_up: auto update by pre-commit hooks
pre-commit-ci[bot] Apr 1, 2024
d08673f
Merge pull request #80 from PAICookers/pre-commit-ci-update-config
KafCoppelia Apr 2, 2024
48e78d5
🐛 bugfix: treat weights as 8 bit if weight_bit_opt is diabled
KafCoppelia Apr 1, 2024
1b1e149
🚸 updated exception description in axon2lcn check
KafCoppelia Apr 2, 2024
de536bd
✨ added property weight_precision for CoreBlock to determine the wp o…
KafCoppelia Apr 2, 2024
3c3edbb
🎨 updated typing
KafCoppelia Apr 2, 2024
10b608d
✅ added tests for setting coarse dtype of weights
KafCoppelia Apr 2, 2024
ba465bd
✅ added tests for weight_bit_optim option
KafCoppelia Apr 2, 2024
c62a183
📝 updated TODO & changelog
KafCoppelia Apr 2, 2024
8496e60
✨ set coarse dtype for raw weights when instantiating Transform
KafCoppelia Apr 3, 2024
09a3166
:rotating_light: auto fix by pre-commit hooks
pre-commit-ci[bot] Apr 3, 2024
c4a1b1a
Merge pull request #81 from PAICookers/bugfix-1
KafCoppelia Apr 3, 2024
b6ae4e0
🔥 removed fm_order of conv1d, conv2d
KafCoppelia Apr 3, 2024
6c27717
✅ added test cases & sync changes
KafCoppelia Apr 3, 2024
4843727
⚡️ use `np.ravel` for faster speed
KafCoppelia Apr 3, 2024
95327ed
📝 updated docs
KafCoppelia Apr 3, 2024
d967fa6
⚡️ Wasted cores will be configured to a reset state
KafCoppelia Apr 8, 2024
6d69f80
✅ added tests for exporting config frames for wasted core placements
KafCoppelia Apr 8, 2024
c15deeb
🐛 bugfix: core blocks connected to the input nodes will be grouped in…
KafCoppelia Apr 10, 2024
e43ff59
♻️ Refactored the code for exporting network configuration
KafCoppelia Apr 10, 2024
09d48f7
✅ added tests for network with more than one input nodes
KafCoppelia Apr 10, 2024
72a3cdc
🥅 updated repr in _degree_check
KafCoppelia Apr 10, 2024
e5e3efc
fix routing group
birdswimming Apr 10, 2024
de8963c
:rotating_light: auto fix by pre-commit hooks
pre-commit-ci[bot] Apr 10, 2024
d83f2e0
Merge pull request #82 from birdswimming/bugfix-1
KafCoppelia Apr 11, 2024
da259ef
🩹 improved the bugfix of wrong routing groups
KafCoppelia Apr 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✅ added tests for exporting config frames for wasted core placements
  • Loading branch information
KafCoppelia committed Apr 10, 2024
commit 6d69f80459bcc79b8575dbdea4306105bc1b8d24
54 changes: 48 additions & 6 deletions tests/backend/conftest.py
Original file line number Diff line number Diff line change
@@ -22,8 +22,14 @@
from paicorelib import WeightPrecision as WP

import paibox as pb
from paibox.backend.conf_template import CoreConfig, CorePlacementConfig, NeuronConfig
from paibox.backend.conf_template import (
EmptyCorePlacementConfig,
CoreConfig,
CorePlacementConfig,
NeuronConfig,
)
from paibox.backend.routing import RoutingCluster
from paibox.exceptions import ResourceError
from paibox.naming import clear_name_cache
from paibox.node import NodeList
from tests.conftest import ParametrizedTestData
@@ -40,6 +46,9 @@ def ensure_dump_dir():
f.unlink()

yield p
# Clean up
# for f in p.iterdir():
# f.unlink()


@pytest.fixture
@@ -170,12 +179,19 @@ class NetForTest4(pb.Network):
N1 -> S3 -> N3 -> S5 -> N4
"""

def __init__(self):
def __init__(self, large_scale: bool = False):
super().__init__()

self.inp1 = pb.InputProj(input=1, shape_out=(400,), name="inp1")
self.n1 = pb.TonicSpiking(800, 3, name="n1", tick_wait_start=1)
self.n2 = pb.TonicSpiking(400, 4, name="n2", tick_wait_start=2)
self.n3 = pb.TonicSpiking(400, 4, name="n3", tick_wait_start=2)

if large_scale:
self.n2 = pb.TonicSpiking(1500, 4, name="n2", tick_wait_start=2)
self.n3 = pb.TonicSpiking(1500, 4, name="n3", tick_wait_start=2)
else:
self.n2 = pb.TonicSpiking(400, 4, name="n2", tick_wait_start=2)
self.n3 = pb.TonicSpiking(400, 4, name="n3", tick_wait_start=2)

self.n4 = pb.TonicSpiking(400, 4, name="n4", tick_wait_start=3)
self.s1 = pb.FullConn(
self.inp1, self.n1, conn_type=pb.SynConnType.All2All, name="s1"
@@ -187,10 +203,10 @@ def __init__(self):
self.n1, self.n3, conn_type=pb.SynConnType.All2All, name="s3"
)
self.s4 = pb.FullConn(
self.n2, self.n4, conn_type=pb.SynConnType.One2One, name="s4"
self.n2, self.n4, conn_type=pb.SynConnType.All2All, name="s4"
)
self.s5 = pb.FullConn(
self.n3, self.n4, conn_type=pb.SynConnType.One2One, name="s5"
self.n3, self.n4, conn_type=pb.SynConnType.All2All, name="s5"
)


@@ -515,6 +531,10 @@ def build_example_net4():
return NetForTest4()


@pytest.fixture(scope="class")
def build_example_net4_large_scale():
return NetForTest4(large_scale=True)

@pytest.fixture(scope="class")
def build_multi_onodes_net():
return Network_with_multi_onodes()
@@ -626,6 +646,11 @@ def MockCorePlacementConfig(MockCoreConfigDict, MockNeuronConfig):
return cpc


@pytest.fixture
def MockEmptyCorePlacementConfig(MockCoreConfigDict):
return EmptyCorePlacementConfig.encapsulate(MockCoreConfigDict)


def packbits_ref(bits: np.ndarray, count: int) -> int:
"""Pack unsigned bits into a signed integer.

@@ -659,6 +684,23 @@ def packbits1():
return partial(packbits_ref, count=1)



def n_axon2lcn_ex_proto(n_axon, n_fanin_max) -> LCN_EX:
"""Convert #N(of axons) to `LCN_EX` & check.

NOTE: LCN_EX = log2[ceil(#N/fan-in per dendrite)], where `LCN_1X` = 0.
"""
if n_axon < 1:
raise ValueError(f"the number of axons must be positive, but got {n_axon}.")

if (lcn := ((n_axon - 1) // n_fanin_max).bit_length()) > LCN_EX.LCN_64X:
raise ResourceError(
f"required LCN extension out of range {LCN_EX.LCN_64X} ({lcn}). "
)

return LCN_EX(lcn)


class TestData:

toposort_data = ParametrizedTestData(
8 changes: 8 additions & 0 deletions tests/backend/test_conf_template.py
Original file line number Diff line number Diff line change
@@ -23,3 +23,11 @@ def test_CorePlacementConfig_instance(
json.dump(
MockCorePlacementConfig.__json__(), f, indent=4, ensure_ascii=True
)

def test_EmptyCorePlacementConfig_instance(
self, ensure_dump_dir, MockEmptyCorePlacementConfig
):
with open(ensure_dump_dir / "empty_core_placement.json", "w") as f:
json.dump(
MockEmptyCorePlacementConfig.__json__(), f, indent=4, ensure_ascii=True
)
9 changes: 9 additions & 0 deletions tests/backend/test_mapper.py
Original file line number Diff line number Diff line change
@@ -234,6 +234,15 @@ def test_export_multi_nodes_more_than_32(

assert len(mapper.graph_info["output"].keys()) == net.n_onodes

def test_export_empty_cplm(self, build_example_net4_large_scale, ensure_dump_dir):
net = build_example_net4_large_scale
mapper = pb.Mapper()
mapper.build(net)
mapper.compile()
mapper.export(fp=ensure_dump_dir)

assert len(mapper.routing_groups[1].wasted_coords) == 2


class TestMapper_Weight4:
@pytest.mark.skipif(
10 changes: 6 additions & 4 deletions tests/backend/test_placement.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from paicorelib import WeightPrecision as WP

import paibox as pb
from paibox.backend.placement import NeuSeg, n_axon2lcn_ex
from paibox.backend.placement import NeuSeg
from paibox.exceptions import ResourceError


@@ -238,7 +238,7 @@ def test_weight_ram_mapping(self, shape, wp, nfold):
if nbit > 1:
w_unpacked = self._weight_ram_mapping_ref(w_folded, nbit)
else:
w_unpacked = w_folded.copy().astype(np.bool_)
w_unpacked = w_folded.astype(np.bool_)

w_unpacked.setflags(write=False)

@@ -390,8 +390,10 @@ def test_weight_ram_mapping_2bits(self, packbits2):


def test_n_axon2lcn_ex():
lcn_ex = n_axon2lcn_ex(1152 * 18 + 1, 1152)
from .conftest import n_axon2lcn_ex_proto

lcn_ex = n_axon2lcn_ex_proto(1152 * 18 + 1, 1152)
assert lcn_ex == LCN_EX.LCN_32X

with pytest.raises(ResourceError):
lcn_ex = n_axon2lcn_ex(1152 * 64 + 1, 1152)
lcn_ex = n_axon2lcn_ex_proto(1152 * 64 + 1, 1152)
10 changes: 7 additions & 3 deletions tests/backend/test_segment_utils.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
from paicorelib import WeightPrecision as WP

import paibox as pb
from paibox.backend.placement import NeuSeg, n_axon2lcn_ex
from paibox.backend.placement import NeuSeg
from paibox.backend.segment_utils import (
aligned_coords,
get_axon_segments,
@@ -349,7 +349,9 @@ def test_get_neu_segments_both(self, neurons, capacity, wp, lcn_ex, expected):
],
)
def test_get_axon_segments(axons):
lcn_ex = n_axon2lcn_ex(sum(axon.num_out for axon in axons), 1152)
from .conftest import n_axon2lcn_ex_proto

lcn_ex = n_axon2lcn_ex_proto(sum(axon.num_out for axon in axons), 1152)

tr_max = 1 << lcn_ex

@@ -368,7 +370,9 @@ def test_get_axon_segments(axons):
)
def test_get_axon_segments_boundary(axons):
"""Illegal boundary cases."""
lcn_ex = n_axon2lcn_ex(sum(axon.num_out for axon in axons), 1152)
from .conftest import n_axon2lcn_ex_proto

lcn_ex = n_axon2lcn_ex_proto(sum(axon.num_out for axon in axons), 1152)
tr_max = 1 << lcn_ex

with pytest.raises(ResourceError):