mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 17:17:14 +08:00
polish code with new pre-commit rule (#2923)
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
""" UT for air_topp_sampling kernel """
|
||||
"""UT for air_topp_sampling kernel"""
|
||||
|
||||
import subprocess
|
||||
import unittest
|
||||
@@ -23,7 +23,6 @@ import fastdeploy.model_executor.ops.gpu
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Initialize.
|
||||
@@ -32,8 +31,7 @@ class Test(unittest.TestCase):
|
||||
np.random.seed(42)
|
||||
print(paddle.device.cuda.get_device_properties())
|
||||
print(paddle.__git_commit__)
|
||||
nvcc_output = subprocess.check_output(["nvcc", "--version"],
|
||||
universal_newlines=True)
|
||||
nvcc_output = subprocess.check_output(["nvcc", "--version"], universal_newlines=True)
|
||||
output = nvcc_output.split()
|
||||
release_idx = output.index("release") + 1
|
||||
self.nvcc_cuda_version = float(output[release_idx].split(",")[0])
|
||||
@@ -49,15 +47,15 @@ class Test(unittest.TestCase):
|
||||
x = paddle.randn([bsz, vocab_size])
|
||||
x = paddle.nn.functional.softmax(x)
|
||||
x = paddle.cast(x, "float32")
|
||||
top_ps = paddle.to_tensor(
|
||||
np.random.uniform(0, 1, [bsz]).astype(np.float32))
|
||||
top_ps = paddle.to_tensor(np.random.uniform(0, 1, [bsz]).astype(np.float32))
|
||||
_, next_tokens = fastdeploy.model_executor.ops.gpu.air_topp_sampling(
|
||||
x.cuda(), top_ps.cuda(), None, None, seed=0, k=1, mode="truncated")
|
||||
x.cuda(), top_ps.cuda(), None, None, seed=0, k=1, mode="truncated"
|
||||
)
|
||||
print(next_tokens)
|
||||
less_than_zero = next_tokens >= 0
|
||||
greater_than_vocab_size = next_tokens <= vocab_size
|
||||
accuracy = paddle.logical_and(less_than_zero, greater_than_vocab_size)
|
||||
print(f'Accuracy of results: {accuracy}')
|
||||
print(f"Accuracy of results: {accuracy}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user