google-research

Форк
0
47 строк · 1.6 Кб
1
# coding=utf-8
2
# Copyright 2024 The Google Research Authors.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
"""Tests for special2."""
17

18
from absl.testing import absltest
19
import jax
20
import jax.numpy as jnp
21
import numpy as np
22

23
from scaling_transformer_inference_efficiency import special2
24

25

26
class Special2Test(absltest.TestCase):
27

28
  def test_softmax2(self):
29
    x = jax.random.normal(jax.random.PRNGKey(0), (8,), jnp.float32)
30
    expected = jax.nn.softmax(x)
31
    actual = special2.softmax2(x * special2.LOG2_E)
32
    np.testing.assert_allclose(expected, actual, rtol=1e-6)
33

34
  def test_logsumexp2(self):
35
    x = jax.random.normal(jax.random.PRNGKey(0), (2, 8), jnp.float32)
36
    expected = jax.scipy.special.logsumexp(x, axis=-1)
37
    actual = special2.logsumexp2(x * special2.LOG2_E) * special2.LN_2
38
    np.testing.assert_allclose(expected, actual, rtol=1e-6)
39

40
  def test_swish(self):
41
    x = jax.random.normal(jax.random.PRNGKey(0), (2, 8), jnp.float32)
42
    expected = jax.nn.swish(x)
43
    actual = special2.swish2(x * 0.5)
44
    np.testing.assert_allclose(expected, actual, rtol=1e-6)
45

46
if __name__ == '__main__':
47
  absltest.main()
48

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.