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

Linter #1516

Closed
wants to merge 61 commits into from
Closed

Linter #1516

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4e1bc11
Create security.py
Smartappli Jun 6, 2024
1cf6f4d
Rename security.py to security.yml
Smartappli Jun 6, 2024
d9c5165
Update security.yml
Smartappli Jun 6, 2024
bccb85d
Update security.yml
Smartappli Jun 6, 2024
527f98e
Update security.yml
Smartappli Jun 6, 2024
dbf7d59
Update security.yml
Smartappli Jun 6, 2024
c1184cc
Update and rename security.yml to linter.yml
Smartappli Jun 6, 2024
fc232d9
Update linter.yml
Smartappli Jun 6, 2024
c033ba8
Update linter.yml
Smartappli Jun 7, 2024
e08fe44
Update _utils.py
Smartappli Jun 16, 2024
439c225
Update llama_tokenizer.py
Smartappli Jun 16, 2024
350efe2
Update __init__.py
Smartappli Jun 16, 2024
d802d14
Update llama_types.py
Smartappli Jun 16, 2024
a1644a0
Update server.py
Smartappli Jun 16, 2024
544c892
Update main.py
Smartappli Jun 16, 2024
740fbf7
Update llama_speculative.py
Smartappli Jun 16, 2024
e8a8e34
Update common.py
Smartappli Jun 16, 2024
b79c8ee
Update Chat.py
Smartappli Jun 16, 2024
1de7f4c
Update quantize.py
Smartappli Jun 16, 2024
3f93ba1
Update low_level_api_llama_cpp.py
Smartappli Jun 16, 2024
6f297f1
Update Miku.py
Smartappli Jun 16, 2024
d21ea00
Update errors.py
Smartappli Jun 16, 2024
b123fbc
Update __main__.py
Smartappli Jun 16, 2024
cde72cd
Update cli.py
Smartappli Jun 16, 2024
3faa2f2
Update _logger.py
Smartappli Jun 16, 2024
932afdf
Update low_level_api_chat_cpp.py
Smartappli Jun 16, 2024
3be6b6e
Update ReasonAct.py
Smartappli Jun 16, 2024
4d07a0d
Update util.py
Smartappli Jun 16, 2024
dfe5462
Update server.py
Smartappli Jun 16, 2024
6f1c85b
Update local.py
Smartappli Jun 16, 2024
e7c6a79
Update llm.py
Smartappli Jun 16, 2024
9394fe4
Update fastapi_server.py
Smartappli Jun 16, 2024
efa4a49
Update langchain_custom_llm.py
Smartappli Jun 16, 2024
65ccf71
Update high_level_api_streaming.py
Smartappli Jun 16, 2024
a2643dd
Update high_level_api_inference.py
Smartappli Jun 16, 2024
cddf149
Merge branch 'main' into patch-1
Smartappli Jun 16, 2024
66a0ead
Update errors.py
Smartappli Jun 16, 2024
a72c4c9
Update __init__.py
Smartappli Jun 16, 2024
437e2e9
Update llama_types.py
Smartappli Jun 16, 2024
cf716a8
Update low_level_api_chat_cpp.py
Smartappli Jun 16, 2024
a56b47d
Update _internals.py
Smartappli Jun 16, 2024
abdf70e
Update types.py
Smartappli Jun 16, 2024
b3ea783
Update model.py
Smartappli Jun 16, 2024
ed573c4
Update llama_cpp.py
Smartappli Jun 16, 2024
e3eca40
Update settings.py
Smartappli Jun 16, 2024
b2f7315
Update llama_cache.py
Smartappli Jun 16, 2024
6b5f026
Update llava_cpp.py
Smartappli Jun 16, 2024
b93b667
Update app.py
Smartappli Jun 16, 2024
8543d0c
Update _internals.py
Smartappli Jun 16, 2024
df4cbeb
Update app.py
Smartappli Jun 16, 2024
95fdf80
Update llama_cpp.py
Smartappli Jun 16, 2024
40d6944
Update llava_cpp.py
Smartappli Jun 16, 2024
3176f99
Update llama.py
Smartappli Jun 16, 2024
ba725de
Update llama.py
Smartappli Jun 16, 2024
93f2957
Update llama_chat_format.py
Smartappli Jun 16, 2024
5975963
Update _internals.py
Smartappli Jun 16, 2024
267b1d9
Update langchain_custom_llm.py
Smartappli Jun 16, 2024
c96df87
Update llama.py
Smartappli Jun 16, 2024
a6fe491
Merge branch 'main' into patch-1
Smartappli Jun 23, 2024
46afec8
Update langchain_custom_llm.py
Smartappli Jun 23, 2024
71030b2
Update low_level_api_chat_cpp.py
Smartappli Jun 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Ruff

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '30 3 * * *'

permissions:
contents: read

jobs:
ruff:
name: Ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- uses: chartboost/ruff-action@v1
with:
args: 'check --select B,F,I,PERF,NPY,PL,RUF,S,SIM,UP --output-format github --diff --exclude docker,docs,scripts,tests,vendor'
2 changes: 0 additions & 2 deletions examples/batch-processing/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

app = FastAPI()

import openai.types.chat as types

@app.post("/v1/chat/completions")
def create_chat_completions():
return {"message": "Hello World"}
4 changes: 2 additions & 2 deletions examples/gradio_chat/local.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import gradio as gr

import llama_cpp
import llama_cpp.llama_tokenizer

import gradio as gr

llama = llama_cpp.Llama.from_pretrained(
repo_id="Qwen/Qwen1.5-0.5B-Chat-GGUF",
filename="*q8_0.gguf",
Expand Down
1 change: 0 additions & 1 deletion examples/gradio_chat/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import gradio as gr

from openai import OpenAI

client = OpenAI(
Expand Down
3 changes: 1 addition & 2 deletions examples/hf_pull/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import llama_cpp
import llama_cpp.llama_tokenizer


llama = llama_cpp.Llama.from_pretrained(
repo_id="Qwen/Qwen1.5-0.5B-Chat-GGUF",
filename="*q8_0.gguf",
Expand Down Expand Up @@ -36,4 +35,4 @@
continue
print(delta["content"], end="", flush=True)

print()
print()
1 change: 1 addition & 0 deletions examples/high_level_api/fastapi_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

"""
import os

import uvicorn

from llama_cpp.server.app import create_app
Expand Down
2 changes: 1 addition & 1 deletion examples/high_level_api/high_level_api_inference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
import argparse
import json

from llama_cpp import Llama

Expand Down
2 changes: 1 addition & 1 deletion examples/high_level_api/high_level_api_streaming.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
import argparse
import json

from llama_cpp import Llama

Expand Down
8 changes: 4 additions & 4 deletions examples/high_level_api/langchain_custom_llm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import argparse

from llama_cpp import Llama
from typing import Any, List, Mapping, Optional

from langchain.llms.base import LLM
from typing import Optional, List, Mapping, Any

from llama_cpp import Llama


class LlamaLLM(LLM):
Expand Down Expand Up @@ -42,8 +42,8 @@ def _identifying_params(self) -> Mapping[str, Any]:
print(f"Answer: {answer.strip()}")

# Using in a chain
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate

prompt = PromptTemplate(
input_variables=["product"],
Expand Down
6 changes: 5 additions & 1 deletion examples/low_level_api/Chat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/python
import sys, os, datetime
import datetime
import os
import sys

from common import GptParams
from low_level_api_chat_cpp import LLaMAInteract


def env_or_def(env, default):
if (env in os.environ):
return os.environ[env]
Expand Down
5 changes: 4 additions & 1 deletion examples/low_level_api/Miku.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/python
import sys, os
import os
import sys

from common import GptParams
from low_level_api_chat_cpp import LLaMAInteract


def env_or_def(env, default):
if (env in os.environ):
return os.environ[env]
Expand Down
7 changes: 5 additions & 2 deletions examples/low_level_api/ReasonAct.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/bin/python
import sys, os, datetime
import os
import sys

from common import GptParams
from low_level_api_chat_cpp import LLaMAInteract


def env_or_def(env, default):
if (env in os.environ):
return os.environ[env]
return default

MODEL = env_or_def("MODEL", "./models/llama-13B/ggml-model.bin")

prompt=f"""You run in a loop of Thought, Action, Observation.
prompt="""You run in a loop of Thought, Action, Observation.
At the end of the loop either Answer or restate your Thought and Action.
Use Thought to describe your thoughts about the question you have been asked.
Use Action to run one of these actions available to you:
Expand Down
3 changes: 1 addition & 2 deletions examples/low_level_api/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import argparse
import os
import re

from dataclasses import dataclass, field
from typing import List

Expand Down
47 changes: 24 additions & 23 deletions examples/low_level_api/low_level_api_chat_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"""
import ctypes
import sys
from time import time
from os import cpu_count, path
from time import time

import llama_cpp
from common import GptParams, gpt_params_parse, gpt_random_prompt
import util
from common import GptParams, gpt_params_parse, gpt_random_prompt

import llama_cpp


# A LLaMA interactive session
class LLaMAInteract:
Expand Down Expand Up @@ -130,13 +132,13 @@ def __init__(self, params: GptParams) -> None:
self.params.n_ctx,
ctypes.byref(_n_token_count_out)
) != 1):
print(f"error: failed to load session file '{self.params.path_session}'", file=sys.stderr)
print("error: failed to load session file", file=sys.stderr)
return
_n_token_count_out = _n_token_count_out.value
self.session_tokens = _session_tokens[:_n_token_count_out]
print(f"loaded a session with prompt size of {_n_token_count_out} tokens", file=sys.stderr)
else:
print(f"session file does not exist, will create", file=sys.stderr)
print("session file does not exist, will create", file=sys.stderr)

# tokenize the prompt
self.embd = []
Expand All @@ -154,7 +156,7 @@ def __init__(self, params: GptParams) -> None:
self.n_matching_session_tokens += 1

if self.n_matching_session_tokens >= len(self.embd_inp):
print(f"session file has exact match for prompt!")
print("session file has exact match for prompt!")
elif self.n_matching_session_tokens < (len(self.embd_inp) / 2):
print(f"warning: session file has low similarity to prompt ({self.n_matching_session_tokens} / {len(self.embd_inp)} tokens); will mostly be reevaluated")
else:
Expand Down Expand Up @@ -374,24 +376,23 @@ def generate(self):
if self.params.temp <= 0:
# Greedy sampling
id = llama_cpp.llama_sample_token_greedy(self.ctx, candidates_p)
elif self.params.mirostat == 1:
mirostat_mu = 2.0 * self.params.mirostat_tau
mirostat_m = 100
llama_cpp.llama_sample_temperature(self.ctx, candidates_p, llama_cpp.c_float(self.params.temp))
id = llama_cpp.llama_sample_token_mirostat(self.ctx, candidates_p, llama_cpp.c_float(self.params.mirostat_tau), llama_cpp.c_float(self.params.mirostat_eta), llama_cpp.c_int(mirostat_m), llama_cpp.c_float(mirostat_mu))
elif self.params.mirostat == 2:
mirostat_mu = 2.0 * self.params.mirostat_tau
llama_cpp.llama_sample_temperature(self.ctx, candidates_p, llama_cpp.c_float(self.params.temp))
id = llama_cpp.llama_sample_token_mirostat_v2(self.ctx, candidates_p, llama_cpp.c_float(self.params.mirostat_tau), llama_cpp.c_float(self.params.mirostat_eta), llama_cpp.c_float(mirostat_mu))
else:
if self.params.mirostat == 1:
mirostat_mu = 2.0 * self.params.mirostat_tau
mirostat_m = 100
llama_cpp.llama_sample_temperature(self.ctx, candidates_p, llama_cpp.c_float(self.params.temp))
id = llama_cpp.llama_sample_token_mirostat(self.ctx, candidates_p, llama_cpp.c_float(self.params.mirostat_tau), llama_cpp.c_float(self.params.mirostat_eta), llama_cpp.c_int(mirostat_m), llama_cpp.c_float(mirostat_mu))
elif self.params.mirostat == 2:
mirostat_mu = 2.0 * self.params.mirostat_tau
llama_cpp.llama_sample_temperature(self.ctx, candidates_p, llama_cpp.c_float(self.params.temp))
id = llama_cpp.llama_sample_token_mirostat_v2(self.ctx, candidates_p, llama_cpp.c_float(self.params.mirostat_tau), llama_cpp.c_float(self.params.mirostat_eta), llama_cpp.c_float(mirostat_mu))
else:
# Temperature sampling
llama_cpp.llama_sample_top_k(self.ctx, candidates_p, top_k, min_keep=llama_cpp.c_size_t(1))
llama_cpp.llama_sample_tail_free(self.ctx, candidates_p, llama_cpp.c_float(self.params.tfs_z), min_keep=llama_cpp.c_size_t(1))
llama_cpp.llama_sample_typical(self.ctx, candidates_p, llama_cpp.c_float(self.params.typical_p), min_keep=llama_cpp.c_size_t(1))
llama_cpp.llama_sample_top_p(self.ctx, candidates_p, llama_cpp.c_float(self.params.top_p), min_keep=llama_cpp.c_size_t(1))
llama_cpp.llama_sample_temperature(self.ctx, candidates_p, llama_cpp.c_float(self.params.temp))
id = llama_cpp.llama_sample_token(self.ctx, candidates_p)
# Temperature sampling
llama_cpp.llama_sample_top_k(self.ctx, candidates_p, top_k, min_keep=llama_cpp.c_size_t(1))
llama_cpp.llama_sample_tail_free(self.ctx, candidates_p, llama_cpp.c_float(self.params.tfs_z), min_keep=llama_cpp.c_size_t(1))
llama_cpp.llama_sample_typical(self.ctx, candidates_p, llama_cpp.c_float(self.params.typical_p), min_keep=llama_cpp.c_size_t(1))
llama_cpp.llama_sample_top_p(self.ctx, candidates_p, llama_cpp.c_float(self.params.top_p), min_keep=llama_cpp.c_size_t(1))
llama_cpp.llama_sample_temperature(self.ctx, candidates_p, llama_cpp.c_float(self.params.temp))
id = llama_cpp.llama_sample_token(self.ctx, candidates_p)
# print("`{}`".format(candidates_p.size))

self.last_n_tokens.pop(0)
Expand Down
2 changes: 1 addition & 1 deletion examples/low_level_api/low_level_api_llama_cpp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ctypes
import os
import multiprocessing
import os

import llama_cpp

Expand Down
3 changes: 2 additions & 1 deletion examples/low_level_api/quantize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import argparse
import os

import llama_cpp


Expand Down
2 changes: 1 addition & 1 deletion examples/low_level_api/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def append(self, elem):

def __getitem__(self, val):
if isinstance(val, int):
if 0 > val or val >= self.size:
if val < 0 or val >= self.size:
raise IndexError('Index out of range')
return self.list[val] if self.size < self.maxsize else self.list[(self.offset + val) % self.maxsize]
elif isinstance(val, slice):
Expand Down
5 changes: 4 additions & 1 deletion examples/ray/llm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from starlette.requests import Request
from typing import Dict

from ray import serve
from ray.serve import Application
from starlette.requests import Request

from llama_cpp import Llama


@serve.deployment
class LlamaDeployment:
def __init__(self, model_path: str):
Expand Down
4 changes: 2 additions & 2 deletions llama_cpp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .llama_cpp import *
from .llama import *
from .llama_cpp import *

__version__ = "0.2.79"
__version__ = "0.2.79"
Loading
Loading