{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84795,"databundleVersionId":10934030,"sourceType":"competition"},{"sourceId":218890054,"sourceType":"kernelVersion"},{"sourceId":219188266,"sourceType":"kernelVersion"},{"sourceId":162855,"sourceType":"modelInstanceVersion","modelInstanceId":138488,"modelId":161088}],"dockerImageVersionId":30839,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# https://www.kaggle.com/discussions/product-feedback/554027\nimport socket\nREMOTE_SERVER = \"one.one.one.one\"\ndef is_connected(hostname):\n  try:\n    # See if we can resolve the host name - tells us if there is\n    # A DNS listening\n    host = socket.gethostbyname(hostname)\n    # Connect to the host - tells us if the host is actually reachable\n    s = socket.create_connection((host, 80), 2)\n    s.close()\n    return True\n  except Exception:\n     pass # We ignore any errors, returning False\n  return False\nprint('Internet :',is_connected(REMOTE_SERVER))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-02T12:48:05.995759Z","iopub.execute_input":"2025-02-02T12:48:05.995975Z","iopub.status.idle":"2025-02-02T12:48:06.025507Z","shell.execute_reply.started":"2025-02-02T12:48:05.995947Z","shell.execute_reply":"2025-02-02T12:48:06.024915Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n!python -m pip install  /kaggle/input/browser-notifications-in-a-kaggle-kernel/*.whl \n!python -m pip install jupyter -q --no-index --find-links=/kaggle/input/browser-notifications-in-a-kaggle-kernel/ \n!python -m pip install -q /kaggle/input/browser-notifications-in-a-kaggle-kernel/jupyter-notify/dist/jupyternotify-0.1.15-py2.py3-none-any.whl --no-index\n","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%reload_ext jupyternotify","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%env PIP_TARGET=/kaggle/working","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!python3.10 -m pip install vllm --find-links /kaggle/input/vllm-nb-na -q  2>&- >&-\n!python3.10 -m pip install triton==3.1.0 --find-links /kaggle/input/vllm-nb-na\n!python3.10 -m pip uninstall pynvml -y\n","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nimport subprocess\nlog_file = open(\"/kaggle/working/vllm_output.log\", \"w\")\nmodel_path = \"/kaggle/input/qwen2.5-coder/transformers/32b-instruct/1\"\nmodel_path = \"/kaggle/input/mistral-small-24b/transformers/mistral-small-24b-instruct-2501/1\"\n\n# background task\ncommand = [\n    \"python3.10\", \n    \"-m\", \n    \"vllm.scripts\", \n    \"serve\",\n    model_path,\n    \"--tensor_parallel_size\", \"4\",\n    \"--gpu_memory_utilization\", \"0.99\",\n    \"--enforce_eager\",\n    \"--enable_prefix_caching\",\n]\n\nprocess = subprocess.Popen(command, stdout=log_file, stderr=log_file)\n\nprint(f\"Background process started with PID: {process.pid}\")","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# from time import sleep\n# sleep(2)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ps -p 22702  ","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip show vllm","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# !pkill -9 19995 \n# !pkill -9 20538 ","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%pwd","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!chmod +x /kaggle/working/triton/backends/nvidia/bin/ptxas","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!tail -n 10 vllm_output.log","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%notify\nimport requests\nimport time\nlast=''\ntry:\n    while True:\n        try:\n            with open('vllm_output.log') as f:\n                a=(f.readlines()[-1])\n                print(a)\n                if 'failed to be inspected' in a or a==last:\n                    break\n                last=a\n            requests.get('http://localhost:8000/v1/models')\n            break\n        except Exception as e:\n            print(end='.')\n            time.sleep(30)\nexcept KeyboardInterrupt:\n    print('KeyboardInterrupt')\n","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nos.environ.pop('PIP_TARGET',None)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# !ps -ef | grep pyngrok","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install pyngrok -q\nfrom pyngrok import ngrok, conf\nfrom kaggle_secrets import UserSecretsClient\nuser_secrets = UserSecretsClient()\nsecret_value_0 = user_secrets.get_secret(\"ngrok_auth_key\")\n\nconf.get_default().auth_token = secret_value_0\npublic_url = ngrok.connect(8000).public_url\npublic_url + '/v1'","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%notify\n!pip install pause -q\nfrom datetime import datetime, timedelta\nfrom pause import until\ndt = datetime.now()\ndt = dt + timedelta(minutes=39, seconds=30)\nprint(dt + timedelta(hours=5, minutes=30))\nuntil(dt)\n\n","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}