|
1 | 1 | [ |
2 | 2 | { |
3 | 3 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=1024.0)\nweights = np.array([0.5, -0.3], dtype=np.float32)\ninputs = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)\ntargets = np.array([1.0, 0.0], dtype=np.float32)\nloss = mp.forward(weights, inputs, targets)\nprint(f\"Loss: {loss:.4f}\")\nprint(f\"Loss dtype: {type(loss).__name__}\")", |
4 | | - "expected_output": "Loss: 665.0000\nLoss dtype: float32" |
| 4 | + "expected_output": "Loss: 665.0000\nLoss dtype: float" |
5 | 5 | }, |
6 | 6 | { |
7 | 7 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=1024.0)\ngrads = np.array([512.0, -256.0], dtype=np.float32)\nresult = mp.backward(grads)\nprint(f\"Gradients: {result}\")\nprint(f\"Grad dtype: {result.dtype}\")", |
8 | 8 | "expected_output": "Gradients: [ 0.5 -0.25]\nGrad dtype: float32" |
9 | 9 | }, |
10 | 10 | { |
11 | 11 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=512.0)\nweights = np.array([1.0, 0.5], dtype=np.float64)\ninputs = np.array([[2.0, 1.0]], dtype=np.float64)\ntargets = np.array([3.0], dtype=np.float64)\nloss = mp.forward(weights, inputs, targets)\nprint(f\"Loss: {loss:.1f}\")\nprint(f\"Loss dtype: {type(loss).__name__}\")", |
12 | | - "expected_output": "Loss: 128.0\nLoss dtype: float32" |
| 12 | + "expected_output": "Loss: 128.0\nLoss dtype: float" |
13 | 13 | }, |
14 | 14 | { |
15 | 15 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=512.0)\ngrads = np.array([1024.0, 512.0], dtype=np.float16)\nresult = mp.backward(grads)\nprint(f\"Gradients: [{result[0]:.0f} {result[1]:.0f}]\")\nprint(f\"Grad dtype: {result.dtype}\")", |
16 | 16 | "expected_output": "Gradients: [2 1]\nGrad dtype: float32" |
17 | 17 | }, |
18 | 18 | { |
19 | 19 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=100.0)\nweights = np.array([0.1, 0.2], dtype=np.float32)\ninputs = np.array([[1.0, 1.0]], dtype=np.float32)\ntargets = np.array([0.5], dtype=np.float32)\nloss = mp.forward(weights, inputs, targets)\nprint(f\"Loss: {loss:.1f}\")\nprint(f\"Loss dtype: {type(loss).__name__}\")", |
20 | | - "expected_output": "Loss: 4.0\nLoss dtype: float32" |
| 20 | + "expected_output": "Loss: 4.0\nLoss dtype: float" |
21 | 21 | }, |
22 | 22 | { |
23 | 23 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=100.0)\ngrads = np.array([200.0, 100.0], dtype=np.float64)\nresult = mp.backward(grads)\nprint(f\"Gradients: [{result[0]:.0f} {result[1]:.0f}]\")\nprint(f\"Grad dtype: {result.dtype}\")", |
24 | 24 | "expected_output": "Gradients: [2 1]\nGrad dtype: float32" |
25 | 25 | }, |
26 | 26 | { |
27 | 27 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=2048.0)\nweights = np.array([0.25], dtype=np.float64)\ninputs = np.array([[4.0]], dtype=np.float64)\ntargets = np.array([2.0], dtype=np.float64)\nloss = mp.forward(weights, inputs, targets)\nprint(f\"Loss: {loss:.1f}\")\nprint(f\"Loss dtype: {type(loss).__name__}\")", |
28 | | - "expected_output": "Loss: 2048.0\nLoss dtype: float32" |
| 28 | + "expected_output": "Loss: 2048.0\nLoss dtype: float" |
29 | 29 | }, |
30 | 30 | { |
31 | 31 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=2048.0)\ngrads = np.array([np.nan], dtype=np.float16)\nresult = mp.backward(grads)\nprint(f\"Gradients: [{result[0]:.0f}]\")\nprint(f\"Grad dtype: {result.dtype}\")", |
32 | 32 | "expected_output": "Gradients: [0]\nGrad dtype: float32" |
33 | 33 | }, |
34 | 34 | { |
35 | 35 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=256.0)\nweights = np.array([1.0], dtype=np.float16)\ninputs = np.array([[2.0]], dtype=np.float16)\ntargets = np.array([3.0], dtype=np.float16)\nloss = mp.forward(weights, inputs, targets)\nprint(f\"Loss: {loss:.1f}\")\nprint(f\"Loss dtype: {type(loss).__name__}\")", |
36 | | - "expected_output": "Loss: 256.0\nLoss dtype: float32" |
| 36 | + "expected_output": "Loss: 256.0\nLoss dtype: float" |
37 | 37 | }, |
38 | 38 | { |
39 | 39 | "test": "import numpy as np\nmp = MixedPrecision(loss_scale=256.0)\ngrads = np.array([np.inf], dtype=np.float64)\nresult = mp.backward(grads)\nprint(f\"Gradients: [{result[0]:.0f}]\")\nprint(f\"Grad dtype: {result.dtype}\")", |
|
0 commit comments