Livt packages
Livt.ML
Version 1.6.1
Fixed-size quantized inference, tensor storage, attention, and transformer building blocks for Livt.
Published files (132)
tests/activation/StableSoftmax8Test.lvt
namespace Livt.ML.Tests.Activation
using Livt.ML.Activation
/**
* Exercises StableSoftmax8 with a shared fixture instance. Each scenario establishes the
* inputs and state it needs.
*/
@Test
component StableSoftmax8Test
{
// Shared fixture instances, signals, and observation state.
dut: StableSoftmax8
/**
* Creates the shared fixture instances (StableSoftmax8). Tests initialize the state
* required by their scenario.
*/
new()
{
this.dut = new StableSoftmax8()
}
/**
* Checks that Compute s uniform and clears inactive lanes.
*/
@Test
fn ComputesUniformAndClearsInactiveLanes()
{
var scores: int[8]
this.dut.ComputeCount(scores, 8, 1)
assert this.dut.GetOutput(0) == 4096
assert this.dut.GetOutput(7) == 4096
this.dut.ComputeCount(scores, 2, 1)
assert this.dut.GetOutput(0) == 16384
assert this.dut.GetOutput(1) == 16384
assert this.dut.GetOutput(2) == 0
}
/**
* Checks that the component is translation invariant and supports signed scores.
*/
@Test
fn IsTranslationInvariantAndSupportsSignedScores()
{
var first: int[8] = [0, -1, -2, 0, 0, 0, 0, 0]
this.dut.ComputeCount(first, 3, 1)
var first0 = this.dut.GetOutput(0)
var first1 = this.dut.GetOutput(1)
var first2 = this.dut.GetOutput(2)
var shifted: int[8] = [100, 99, 98, 0, 0, 0, 0, 0]
this.dut.ComputeCount(shifted, 3, 1)
assert this.dut.GetOutput(0) == first0
assert this.dut.GetOutput(1) == first1
assert this.dut.GetOutput(2) == first2
assert first0 > first1
assert first1 > first2
}
}