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

added FP preset #705

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions src/aihwkit/simulator/presets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
MixedPrecisionGokmenVlasovPreset,
MixedPrecisionPCMPreset,
)
from .inference import StandardHWATrainingPreset

from .inference import StandardHWATrainingPreset, FloatingPointPreset
from .devices import (
ReRamESPresetDevice,
ReRamSBPresetDevice,
Expand Down
24 changes: 23 additions & 1 deletion src/aihwkit/simulator/presets/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Optional
from dataclasses import dataclass, field

from aihwkit.simulator.configs.configs import InferenceRPUConfig
from aihwkit.simulator.configs.configs import InferenceRPUConfig, TorchInferenceRPUConfig
from aihwkit.simulator.parameters import (
MappingParameter,
IOParameters,
Expand All @@ -34,6 +34,28 @@


# Inference
@dataclass
class FloatingPointPreset(TorchInferenceRPUConfig):
"""Preset configuration for FP-like AIMC (Analog In-Mememory Compute)
accuracy evaluation/training.

This preset configuration does not inject any noise in any form (weight noise
quantization etc.) and is equivalent to the FP model.
"""

mapping: MappingParameter = field(
default_factory=lambda: MappingParameter(max_input_size=0, max_output_size=0)
)

forward: IOParameters = field(default_factory=lambda: IOParameters(is_perfect=True))

pre_post: PrePostProcessingParameter = field(
default_factory=lambda: PrePostProcessingParameter(
input_range=InputRangeParameter(enable=False)
)
)


@dataclass
class StandardHWATrainingPreset(InferenceRPUConfig):
"""Preset configuration for AIMC (Analog In-Mememory Compute)
Expand Down
21 changes: 20 additions & 1 deletion tests/test_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"""Tests for analog presets."""

from torch import Tensor
from torch import Tensor, randn

from aihwkit.simulator.tiles.analog import AnalogTile
from aihwkit.simulator.presets import (
Expand Down Expand Up @@ -50,6 +50,7 @@
TTv2EcRamPreset,
TTv2EcRamMOPreset,
TTv2IdealizedPreset,
FloatingPointPreset,
)
from .helpers.decorators import parametrize_over_presets
from .helpers.testcases import AihwkitTestCase
Expand Down Expand Up @@ -131,3 +132,21 @@ def test_tile_preset(self):
self.assertEqual(tile_biases, None)
# TODO: disabled as the comparison needs to take into account noise
# self.assertTensorAlmostEqual(tile_weights, weights)


class PresetTestFP(AihwkitTestCase):
"""Test for FP preset."""

def test_tile_preset(self):
"""Test fwd behavior of FP preset."""
out_size = 2
in_size = 3
weights = randn(out_size, in_size)
inp = randn(in_size)
fp_out = inp @ weights.T

rpu_config = FloatingPointPreset()
analog_tile = AnalogTile(out_size, in_size, rpu_config, bias=False)
analog_tile.set_weights(weights)
tile_out = analog_tile(inp)
self.assertTensorAlmostEqual(fp_out, tile_out)