Unexpected F401
Fissium opened this issue · comments
Nikita Rubinkovskiy commented
Using the following code in the notebook, ruff shows F401.
from collections import defaultdict
import gradio as gr
import numpy as np
import pandas as pd
import torch
from langchain.embeddings import HuggingFaceEmbeddings
from peft.config import PeftConfig
from peft.peft_model import PeftModel
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, SearchRequest, VectorParams
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
MODEL_NAME = "./checkpoints/checkpoint-465/"
config = PeftConfig.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(
config.base_model_name_or_path,
load_in_8bit=True,
torch_dtype=torch.float16,
device_map="auto",
)
model = PeftModel.from_pretrained(model, MODEL_NAME, torch_dtype=torch.float16)
model.eval()
However, if I use the first imported module that ruff considers unused, F401 disappears.
torch.cuda.is_available()
config = PeftConfig.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(
config.base_model_name_or_path,
load_in_8bit=True,
torch_dtype=torch.float16,
device_map="auto",
)
model = PeftModel.from_pretrained(model, MODEL_NAME, torch_dtype=torch.float16)
model.eval()
But if I use torch.code.is_available()
in the cell above, I still get F401, but not about torch.
My setting.json
:
{
"window.titleBarStyle": "custom",
"workbench.startupEditor": "none",
"extensions.autoUpdate": false,
"explorer.confirmDragAndDrop": false,
"ruff.importStrategy": "useBundled",
"editor.fontFamily": "Fira Code",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.fontLigatures": true,
"files.watcherExclude": {
"**/.venv": true
},
"files.exclude": {
"**/.venv": true
},
"python.analysis.typeCheckingMode": "basic",
"python.analysis.diagnosticMode": "openFilesOnly",
"python.analysis.diagnosticSeverityOverrides": {
"reportUnusedImport": "none",
"reportUnusedVariable": "none",
"reportUndefinedVariable": "none",
"reportUnusedClass": "none",
"reportUnusedExpression": "none",
"reportUnusedFunction": "none",
},
"ruff.lint.args": [
"--select=ARG",
"--select=F",
"--select=E",
"--select=I001",
],
}
VS Code extension versions - v2023.50.0
Environment:
OS: Archlinux
Python: 3.11 (conda env)
Dhruv Manilawala commented
This is because of a bug: astral-sh/ruff#8526
I'll close this in favor of the linked issue.