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/transformer/TransformerBlockTest.lvt

namespace Livt.ML.Tests.Transformer

using Livt.ML.Transformer

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

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

	/**
	 * Checks that Compute s zero input.
	 */
	@Test
	fn ComputesZeroInput()
	{
		block.Clear()

		var input: int[8]

		block.Compute(input)

		assert block.GetOutput(0) == 0
		assert block.GetOutput(7) == 0
	}

	/**
	 * Checks that Compute s non zero input.
	 */
	@Test
	fn ComputesNonZeroInput()
	{
		block.Clear()

		var input: int[8] = [2, 0, 0, 0, 0, 0, 0, 0]

		block.Compute(input)

		assert block.GetOutput(0) == 7
		assert block.GetOutput(1) == 0
	}

	/**
	 * Checks that the component preserves residual signal.
	 */
	@Test
	fn PreservesResidualSignal()
	{
		block.Clear()

		var input: int[8] = [4, 4, 0, 0, 0, 0, 0, 0]

		block.Compute(input)

		assert block.GetOutput(0) > 0
		assert block.GetOutput(1) > 0
	}

	/**
	 * Checks that the component returns zero out of bounds.
	 */
	@Test
	fn ReturnsZeroOutOfBounds()
	{
		block.Clear()

		var input: int[8]

		block.Compute(input)

		assert block.GetOutput(7) == 0
		assert block.GetOutput(8) == 0
	}
}