Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server refactor #23

Merged
merged 1 commit into from
Jun 5, 2024
Merged

Server refactor #23

merged 1 commit into from
Jun 5, 2024

Conversation

jpodivin
Copy link
Collaborator

@jpodivin jpodivin commented May 10, 2024

General code refactoring in anticipation of deployment as a server. The server option is only intended for experimental use, and will not be documented at this time.

Among other changes:

  • prompt has been simplified
  • CLI args now have proper help
  • new optional dependencies for server were specified
  • log retrieval function now has type annotations
  • constants, extractors and utilities were moved into separate submodules

import os
import json

from fastapi import FastAPI

Check warning

Code scanning / vcs-diff-lint

Unable to import 'fastapi' Warning

Unable to import 'fastapi'
import json

from fastapi import FastAPI
from pydantic import BaseModel

Check warning

Code scanning / vcs-diff-lint

Unable to import 'pydantic' Warning

Unable to import 'pydantic'
@jpodivin jpodivin force-pushed the serving branch 2 times, most recently from cf5d8b4 to 751ffba Compare May 15, 2024 06:54
@jpodivin jpodivin changed the title WIP: Serving Server refactor May 15, 2024
@jpodivin jpodivin marked this pull request as ready for review May 15, 2024 07:05
@jpodivin jpodivin requested review from TomasTomecek, jkonecny12 and xsuchy and removed request for TomasTomecek and jkonecny12 May 15, 2024 14:36
from urllib.parse import urlparse
from urllib.request import urlretrieve

import requests

Check warning

Code scanning / vcs-diff-lint

Unable to import 'requests' Warning

Unable to import 'requests'
from urllib.request import urlretrieve

import requests
import progressbar

Check warning

Code scanning / vcs-diff-lint

Unable to import 'progressbar' Warning

Unable to import 'progressbar'
import requests
import progressbar

from llama_cpp import Llama

Check warning

Code scanning / vcs-diff-lint

Unable to import 'llama_cpp' Warning

Unable to import 'llama_cpp'
@@ -0,0 +1,132 @@
import logging

Check warning

Code scanning / vcs-diff-lint

Similar lines in 2 files ==logdetective.logdetective:[63:70] ==logdetective.server:[37:44] log_summary = extractor(log) Warning

Similar lines in 2 files
==logdetective.logdetective:[63:70]
==logdetective.server:[37:44]
log_summary = extractor(log)
@jkonecny12
Copy link
Collaborator

Last commit has a typo impor.

Copy link
Collaborator

@jkonecny12 jkonecny12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just a few nitpicks and questions.

parser.add_argument("-M", "--model", type=str, default=DEFAULT_ADVISOR)
parser.add_argument("-S", "--summarizer", type=str, default="drain")
parser.add_argument("-N", "--n_lines", type=int, default=5)
parser.add_argument("url", type=str, default="", help="The URL of the log file to be analyzed.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also taking local paths now. I think it should be mentioned in help.

type=str, default=DEFAULT_ADVISOR)
parser.add_argument("-S", "--summarizer", type=str, default="drain",
help="Choose between LLM and Drain template miner as the log summarizer.\
LLM must be specified as path to a model, URL or local.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what local means here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the file system.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it needs more explanation. Does it mean path to local model or name of the model in cache directory? If the second how it should be specified.

Could you please improve the help a bit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's path, not a name, the help says that. At no point is any cache mentioned. User shouldn't know about it and he shouldn't even know about it. It's an implementation detail.


import drain3
from drain3.template_miner_config import TemplateMinerConfig
from llama_cpp import Llama, LlamaGrammar

Check warning

Code scanning / vcs-diff-lint

Unable to import 'llama_cpp' Warning

Unable to import 'llama_cpp'
@jpodivin jpodivin force-pushed the serving branch 2 times, most recently from 9858ba1 to 9f2a1f4 Compare May 21, 2024 11:03
@TomasTomecek
Copy link
Collaborator

requests.exceptions.ReadTimeout: HTTPConnectionPool(host='localhost', port=8080): Read timed out. (read timeout=200)

I can see the timeout is configurable but we'll need to increase the default to at least 10 minutes; it's really frustrating to wait just to get timeouted

@TomasTomecek
Copy link
Collaborator

I finally have a successful run \o/
after this is merged, I'll provide docs for readme how to run the server :)

{'content': "[1]:\nThe output of the task shows that the SRPM file was downloaded and extracted successfully.\n\n[2]:\nThe output of the SRPMResults tool confirms the package name, version, and architecture.\n\n[3]:The build log indicates that the build process started and the initial checks were successful.\n\n[4]:\nThe build log shows the first failure during the installation of dependencies. This failure is due to the missing 'librocm-hip-dev' package.\n\n[5]:\nThe second failure occurs during the RPM build process. The error message indicates that the 'gcc-11' compiler is not installed.\n\n[6]:\nThe error message also suggests that the 'gcc-rocm' compiler should be used instead. The 'gcc-rocm' compiler is a part of the 'rocm-devel' package, which is not installed as well.\n\n[7]:\nThe 'rocm-devel' package is not included in the list of dependencies, which wasgenerated from the SRPM file.\n\n[8]:\nThe 'rocm-dev' package, which is required for the 'librocm-hip-dev' package, is not installed either. This package is not included in the list of dependencies as well.\n\nExplanation:\n\nThe issue arises from the missing dependencies in the SRPM file, specifically 'rocm-devel' and 'rocm-dev'. The absence of these packages leads to the installation failures of 'librocm-hip-dev' and 'gcc-rocm'.\n\nThe root cause of this issue lies in the misconfiguration or incorrect generation of the SRPM file. The missing dependencies are likely to be overlooked during the SRPM creation process.\n\nTo resolve the issue, the dependencies should be added to the SRPM file, and the task should be re-run.\n\nTo prevent similar issues from occurring in the future, make sure to double-check the SRPM file for missing dependencies before distributing it. Also, consider installing the required packages during the task setup process, if they are not typically included in the list of dependencies.",
 'id_slot': 0,
 'stop': True,
 'model': '/home/tt/.cache/logdetective/mistral-7b-instruct-v0.2.Q4_K_S.gguf',
 'tokens_predicted': 467,
 'tokens_evaluated': 270,
 'generation_settings': {'n_ctx': 512,
  'n_predict': -1,
  'model': '/home/tt/.cache/logdetective/mistral-7b-instruct-v0.2.Q4_K_S.gguf',
  'seed': 4294967295,
  'temperature': 0.800000011920929,
  'dynatemp_range': 0.0,
  'dynatemp_exponent': 1.0,
  'top_k': 40,
  'top_p': 0.949999988079071,
  'min_p': 0.05000000074505806,
  'tfs_z': 1.0,
  'typical_p': 1.0,
  'repeat_last_n': 64,
  'repeat_penalty': 1.0,
  'presence_penalty': 0.0,
  'frequency_penalty': 0.0,
  'penalty_prompt_tokens': [],
  'use_penalty_prompt_tokens': False,
  'mirostat': 0,
  'mirostat_tau': 5.0,
  'mirostat_eta': 0.10000000149011612,
  'penalize_nl': False,
  'stop': [],
  'n_keep': 0,
  'n_discard': 0,
  'ignore_eos': False,
  'stream': False,
  'logit_bias': [],
  'n_probs': 0,
  'min_keep': 0,
  'grammar': '',
  'samplers': ['top_k',
   'tfs_z',
   'typical_p',
   'top_p',
   'min_p',
   'temperature']},
 'prompt': '\nGiven following log snippets, and nothing else, explain what failure, if any, occured during build of this package.\n\nLogging PID: 6270\n\nTask:\n\n{\'appstream\': False,\n \'background\': False,\n \'build_id\': 7495493,\n \'chroot\': None,\n \'package_name\': None,\n \'project_dirname\': \'review-2279158-python-triton-rocm\',\n \'project_name\': \'review-2279158-python-triton-rocm\',\n \'project_owner\': \'ttomecek\',\n \'repos\': [],\n \'sandbox\': \'ttomecek/review-2279158-python-triton-rocm--ttomecek\',\n \'source_json\': {\'pkg\': \'python-triton-rocm-2.3.0-1.fc41.src.rpm\',\n                 \'tmp\': \'tmpueeppiy3\',\n                 \'url\': \'https://copr.fedorainfracloud.org/tmp/tmpueeppiy3/python-triton-rocm-2.3.0-1.fc41.src.rpm\'},\n \'source_type\': 2,\n \'submitter\': \'ttomecek\',\n \'task_id\': \'7495493\'}\n\n\nOutput: [\'python-triton-rocm-2.3.0-1.fc41.src.rpm\']\n\nRunning SRPMResults tool\n\nPackage info: {\n    "name": "python-triton-rocm",\n    "epoch": null,\n    "version": "2.3.0",\n    "release": "1",\n    "exclusivearch": [\n        "x86_64"\n    ],\n    "excludearch": []\n\n}\n\nSRPMResults finished\n\n\n\nAnalysis of the failure must be in a format of [X] : [Y], where [X] is a log snippet, and [Y] is the explanation.\n\nFinally, drawing on information from all snippets, provide complete explanation of the issue.\n\nAnalysis:\n\n',
 'truncated': True,
 'stopped_eos': True,
 'stopped_word': False,
 'stopped_limit': False,
 'stopping_word': '',
 'tokens_cached': 481,
 'timings': {'prompt_n': 270,
  'prompt_ms': 191864.2,
  'prompt_per_token_ms': 710.6081481481482,
  'prompt_per_second': 1.4072453328969137,
  'predicted_n': 467,
  'predicted_ms': 631375.292,
  'predicted_per_token_ms': 1351.981353319058,
  'predicted_per_second': 0.7396551716819479}}

Copy link
Collaborator

@TomasTomecek TomasTomecek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, none of the comments/suggestions are blocking

self.verbose = verbose
self.context = context

def __call__(self, log: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of callable instances of classes. It looks pretty confusing in the code.

Comment on lines 29 to 30
parser.add_argument("-v", "--verbose", action='count', default=0)
parser.add_argument("-q", "--quiet", action='store_true')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to get logging setup to the server as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the silent option? I was thinking about that and decided against it. The major reason for quiet mode is that all the output pollutes the terminal and makes things difficult to read. But if it's going to run as a server, we don't need to worry about that.

Especially if it's going to be containerized, because in that case the only logs stored for the pod will all belong to our service, and will be easy to filter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I commented on the wrong line

my point is that there is no logger handler for logdetective module when running directly from CLI using fastapi so there are no logs printed in the console; I manually added one while playing with this PR so that I could see what's happening

Copy link
Collaborator

@TomasTomecek TomasTomecek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, still LGTM!

Enabling runtime setting of cluster number

Removing poetry import

Reworked help

New arg for clusters

Adding fastapi dependency

Moved inference and model initialization into utils

Adding pydantic for server

Prompt simplified

We no longer need to notify model about special substrings, now
that we retrieve representative log samples instead of templates.

Exposing n_clusters arg

Restoring local retrieval of logs

Docstrings and import rearangement

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
@jpodivin jpodivin merged commit 7a18d8f into fedora-copr:main Jun 5, 2024
1 of 2 checks passed
@jpodivin jpodivin deleted the serving branch September 13, 2024 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants