config.yml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. version: 2.1
  2. orbs:
  3. python: circleci/python@2
  4. commands:
  5. run_chatgpt_api_test:
  6. parameters:
  7. inference_engine:
  8. type: string
  9. model_id:
  10. type: string
  11. expected_output:
  12. type: string
  13. prompt:
  14. type: string
  15. steps:
  16. - run:
  17. name: Run chatgpt api integration test (<<parameters.inference_engine>>, <<parameters.model_id>>)
  18. command: |
  19. source env/bin/activate
  20. # Start first instance
  21. HF_HOME="$(pwd)/.hf_cache_node1" DEBUG_DISCOVERY=7 DEBUG=7 exo --inference-engine <<parameters.inference_engine>> --node-id "node1" --listen-port 5678 --broadcast-port 5679 --chatgpt-api-port 8000 --chatgpt-api-response-timeout 900 2>&1 | tee output1.log &
  22. PID1=$!
  23. # Start second instance
  24. HF_HOME="$(pwd)/.hf_cache_node2" DEBUG_DISCOVERY=7 DEBUG=7 exo --inference-engine <<parameters.inference_engine>> --node-id "node2" --listen-port 5679 --broadcast-port 5678 --chatgpt-api-port 8001 --chatgpt-api-response-timeout 900 2>&1 | tee output2.log &
  25. PID2=$!
  26. # Wait for discovery
  27. sleep 10
  28. # Function to check if processes are still running
  29. check_processes() {
  30. if ! kill -0 $PID1 2>/dev/null; then
  31. echo "First instance (PID $PID1) died unexpectedly. Log output:"
  32. cat output1.log
  33. exit 1
  34. fi
  35. if ! kill -0 $PID2 2>/dev/null; then
  36. echo "Second instance (PID $PID2) died unexpectedly. Log output:"
  37. cat output2.log
  38. exit 1
  39. fi
  40. }
  41. # Check processes before proceeding
  42. check_processes
  43. # Special handling for dummy engine
  44. if [ "<<parameters.inference_engine>>" = "dummy" ]; then
  45. expected_content="This is a dummy response"
  46. else
  47. expected_content="Michael Jackson"
  48. fi
  49. echo "Sending request to first instance..."
  50. response_1=$(curl -s http://localhost:8000/v1/chat/completions \
  51. -H "Content-Type: application/json" \
  52. -d '{
  53. "model": "<<parameters.model_id>>",
  54. "messages": [{"role": "user", "content": "<<parameters.prompt>>"}],
  55. "temperature": 0.7
  56. }')
  57. echo "Response 1: $response_1"
  58. # Check processes after first response
  59. check_processes
  60. echo "Sending request to second instance..."
  61. response_2=$(curl -s http://localhost:8001/v1/chat/completions \
  62. -H "Content-Type: application/json" \
  63. -d '{
  64. "model": "<<parameters.model_id>>",
  65. "messages": [{"role": "user", "content": "<<parameters.prompt>>"}],
  66. "temperature": 0.7
  67. }')
  68. echo "Response 2: $response_2"
  69. # Check processes after second response
  70. check_processes
  71. # Stop both instances
  72. kill $PID1 $PID2
  73. echo ""
  74. if ! echo "$response_1" | grep -q "<<parameters.expected_output>>" || ! echo "$response_2" | grep -q "<<parameters.expected_output>>"; then
  75. echo "Test failed: Response does not contain '<<parameters.expected_output>>'"
  76. echo "Response 1: $response_1"
  77. echo ""
  78. echo "Response 2: $response_2"
  79. echo "Output of first instance:"
  80. cat output1.log
  81. echo "Output of second instance:"
  82. cat output2.log
  83. exit 1
  84. else
  85. echo "Test passed: Response from both nodes contains '<<parameters.expected_output>>'"
  86. fi
  87. jobs:
  88. unit_test:
  89. macos:
  90. xcode: "16.0.0"
  91. resource_class: m2pro.large
  92. steps:
  93. - checkout
  94. - run:
  95. name: Set up Python
  96. command: |
  97. brew install python@3.12
  98. python3.12 -m venv env
  99. source env/bin/activate
  100. - run:
  101. name: Install dependencies
  102. command: |
  103. source env/bin/activate
  104. pip install --upgrade pip
  105. pip install .
  106. - run:
  107. name: Run tests
  108. command: |
  109. source env/bin/activate
  110. # set TEMPERATURE to 0 for deterministic sampling
  111. echo "Running inference engine tests..."
  112. METAL_DEVICE_WRAPPER_TYPE=1 METAL_DEBUG_ERROR_MODE=0 METAL_XCODE=1 TEMPERATURE=0 python3 -m exo.inference.test_inference_engine
  113. echo "Running tokenizer tests..."
  114. python3 ./test/test_tokenizers.py
  115. discovery_integration_test:
  116. macos:
  117. xcode: "16.0.0"
  118. steps:
  119. - checkout
  120. - run:
  121. name: Set up Python
  122. command: |
  123. brew install python@3.12
  124. python3.12 -m venv env
  125. source env/bin/activate
  126. - run:
  127. name: Install dependencies
  128. command: |
  129. source env/bin/activate
  130. pip install --upgrade pip
  131. pip install .
  132. - run:
  133. name: Run discovery integration test
  134. command: |
  135. source env/bin/activate
  136. DEBUG_DISCOVERY=7 DEBUG=7 exo --node-id "node1" --listen-port 5678 --broadcast-port 5679 --chatgpt-api-port 8000 > output1.log 2>&1 &
  137. PID1=$!
  138. DEBUG_DISCOVERY=7 DEBUG=7 exo --node-id "node2" --listen-port 5679 --broadcast-port 5678 --chatgpt-api-port 8001 > output2.log 2>&1 &
  139. PID2=$!
  140. sleep 10
  141. kill $PID1 $PID2
  142. if grep -q "Peer statuses: {\\'node2\\': \\'is_connected=True, health_check=True" output1.log && ! grep -q "Failed to connect peers:" output1.log && grep -q "Peer statuses: {\\'node1\\': \\'is_connected=True, health_check=True" output2.log && ! grep -q "Failed to connect peers:" output2.log; then
  143. echo "Test passed: Both instances discovered each other"
  144. exit 0
  145. else
  146. echo "Test failed: Devices did not discover each other"
  147. echo "Output of first instance:"
  148. cat output1.log
  149. echo "Output of second instance:"
  150. cat output2.log
  151. exit 1
  152. fi
  153. chatgpt_api_integration_test_mlx:
  154. macos:
  155. xcode: "16.0.0"
  156. resource_class: m2pro.large
  157. steps:
  158. - checkout
  159. - run:
  160. name: Set up Python
  161. command: |
  162. brew install python@3.12
  163. python3.12 -m venv env
  164. source env/bin/activate
  165. - run:
  166. name: Install dependencies
  167. command: |
  168. source env/bin/activate
  169. pip install --upgrade pip
  170. pip install .
  171. - run_chatgpt_api_test:
  172. inference_engine: mlx
  173. model_id: llama-3.2-1b
  174. prompt: "Keep responses concise. Who was the king of pop?"
  175. expected_output: "Michael Jackson"
  176. chatgpt_api_integration_test_dummy:
  177. macos:
  178. xcode: "16.0.0"
  179. resource_class: m2pro.large
  180. steps:
  181. - checkout
  182. - run:
  183. name: Set up Python
  184. command: |
  185. brew install python@3.12
  186. python3.12 -m venv env
  187. source env/bin/activate
  188. - run:
  189. name: Install dependencies
  190. command: |
  191. source env/bin/activate
  192. pip install --upgrade pip
  193. pip install .
  194. - run_chatgpt_api_test:
  195. inference_engine: dummy
  196. model_id: dummy-model
  197. prompt: "Dummy prompt."
  198. expected_output: "dummy"
  199. test_macos_m1:
  200. macos:
  201. xcode: "16.0.0"
  202. resource_class: m2pro.large
  203. steps:
  204. - checkout
  205. - run: system_profiler SPHardwareDataType
  206. # chatgpt_api_integration_test_tinygrad:
  207. # macos:
  208. # xcode: "16.0.0"
  209. # resource_class: m2pro.large
  210. # steps:
  211. # - checkout
  212. # - run:
  213. # name: Set up Python
  214. # command: |
  215. # brew install python@3.12
  216. # python3.12 -m venv env
  217. # source env/bin/activate
  218. # - run:
  219. # name: Install dependencies
  220. # command: |
  221. # source env/bin/activate
  222. # pip install --upgrade pip
  223. # pip install .
  224. # - run_chatgpt_api_test:
  225. # inference_engine: tinygrad
  226. # model_id: llama-3-8b
  227. # prompt: "Keep responses concise. Who was the king of pop?"
  228. # expected_output: "Michael Jackson"
  229. workflows:
  230. version: 2
  231. build_and_test:
  232. jobs:
  233. - unit_test
  234. - discovery_integration_test
  235. - chatgpt_api_integration_test_mlx
  236. - chatgpt_api_integration_test_dummy
  237. - test_macos_m1
  238. # - chatgpt_api_integration_test_tinygrad