You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_plug_text_generation.py 2.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. from modelscope.hub.snapshot_download import snapshot_download
  4. from modelscope.pipelines import pipeline
  5. from modelscope.utils.constant import Tasks
  6. class TextPlugGenerationTest(unittest.TestCase):
  7. def setUp(self) -> None:
  8. # please make sure this local path exists.
  9. self.model_id = 'damo/nlp_plug_text-generation_27B'
  10. self.model_dir = snapshot_download(self.model_id)
  11. self.plug_input = '段誉轻挥折扇,摇了摇头,说道:“你师父是你的师父,你师父可不是我的师父。"'
  12. @unittest.skip('distributed plug, skipped')
  13. def test_plug(self):
  14. """ The model can be downloaded from the link on
  15. https://modelscope.cn/models/damo/nlp_plug_text-generation_27B/summary.
  16. After downloading, you should have a plug model structure like this:
  17. nlp_plug_text-generation_27B
  18. |_ config.json
  19. |_ configuration.json
  20. |_ ds_zero-offload_10B_config.json
  21. |_ vocab.txt
  22. |_ model <-- an empty directory
  23. Model binaries shall be downloaded separately to populate the model directory, so that
  24. the model directory would contain the following binaries:
  25. |_ model
  26. |_ mp_rank_00_model_states.pt
  27. |_ mp_rank_01_model_states.pt
  28. |_ mp_rank_02_model_states.pt
  29. |_ mp_rank_03_model_states.pt
  30. |_ mp_rank_04_model_states.pt
  31. |_ mp_rank_05_model_states.pt
  32. |_ mp_rank_06_model_states.pt
  33. |_ mp_rank_07_model_states.pt
  34. """
  35. # download model binaries to <model_dir>/model
  36. pipe = pipeline(Tasks.text_generation, model=self.model_id)
  37. print(
  38. f'input: {self.plug_input}\noutput: {pipe(self.plug_input, out_length=256)}'
  39. )
  40. if __name__ == '__main__':
  41. unittest.main()