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/linear/Int8Linear4x8Test.lvt

namespace Livt.ML.Tests.Linear

using Livt.ML.Linear

/**
 * Exercises Int8Linear4x8 with a shared fixture instance. Each scenario establishes the
 * inputs and state it needs.
 */
@Test
component Int8Linear4x8Test
{
	// Shared fixture instances, signals, and observation state.
	layer: Int8Linear4x8

	/**
	 * Creates the shared fixture instances (Int8Linear4x8). Tests initialize the state
	 * required by their scenario.
	 */
	new()
	{
		layer = new Int8Linear4x8()
	}

	/**
	 * Checks that Compute s signed weights and biases.
	 */
	@Test
	fn ComputesSignedWeightsAndBiases()
	{
		layer.ClearParameters()
		layer.SetRowValues(0, 1, -2, 3, -4)
		layer.SetBias(0, 10)

		var input: int[4] = [5, 6, 7, 8]
		layer.Compute(input)

		assert layer.GetAccumulator(0) == -8
		assert layer.GetAccumulator(1) == 0
	}

	/**
	 * Checks that the component preserves int32 accumulator results.
	 */
	@Test
	fn PreservesInt32AccumulatorResults()
	{
		layer.ClearParameters()
		layer.SetRowValues(7, 127, 127, 127, 127)
		layer.SetBias(7, 100000)

		var input: int[4] = [127, 127, 127, 127]
		layer.Compute(input)

		assert layer.GetAccumulator(7) == 164516
	}

	/**
	 * Checks that the component ignores invalid rows and getters.
	 */
	@Test
	fn IgnoresInvalidRowsAndGetters()
	{
		layer.ClearParameters()
		layer.SetRowValues(99, 1, 1, 1, 1)
		layer.SetBias(-1, 5)

		var input: int[4] = [1, 1, 1, 1]
		layer.Compute(input)

		assert layer.GetAccumulator(-1) == 0
		assert layer.GetAccumulator(8) == 0
	}
}