Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion libs/community/langchain_community/chat_models/mlx.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,15 @@ def _stream(
top_p: float = model_kwargs.get("top_p", 1.0)
min_p: float = model_kwargs.get("min_p", 0.0)
min_tokens_to_keep: int = model_kwargs.get("min_tokens_to_keep", 1)
top_k: int = model_kwargs.get("top_k", 0)

llm_input = self._to_chat_prompt(messages, tokenize=True, return_tensors="np")

prompt_tokens = mx.array(llm_input[0])

eos_token_id = self.tokenizer.eos_token_id

sampler = make_sampler(temp or 0.0, top_p, min_p, min_tokens_to_keep)
sampler = make_sampler(temp or 0.0, top_p, min_p, min_tokens_to_keep, top_k)

logits_processors = make_logits_processors(
None, repetition_penalty, repetition_context_size
Expand Down
13 changes: 10 additions & 3 deletions libs/community/langchain_community/llms/mlx_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ class MLXPipeline(LLM):
for applying repetition penalty, default is None.
- top_p (float): The cumulative probability threshold for
top-p filtering, default is 1.0.

- min_p (float): The minimum probability threshold for
top-p filtering, default is 0.0.
- min_tokens_to_keep (int): The minimum number of tokens to keep
for top-p filtering, default is 1.
- top_k (int): The number of highest probability vocabulary tokens
to keep for top-k filtering, default is 0.
"""

model_config = ConfigDict(
Expand Down Expand Up @@ -166,8 +171,9 @@ def _call(
top_p: float = pipeline_kwargs.get("top_p", 1.0)
min_p: float = pipeline_kwargs.get("min_p", 0.0)
min_tokens_to_keep: int = pipeline_kwargs.get("min_tokens_to_keep", 1)
top_k: int = pipeline_kwargs.get("top_k", 0)

sampler = make_sampler(temp, top_p, min_p, min_tokens_to_keep)
sampler = make_sampler(temp, top_p, min_p, min_tokens_to_keep, top_k)
logits_processors = make_logits_processors(
None, repetition_penalty, repetition_context_size
)
Expand Down Expand Up @@ -214,6 +220,7 @@ def _stream(
top_p: float = pipeline_kwargs.get("top_p", 1.0)
min_p: float = pipeline_kwargs.get("min_p", 0.0)
min_tokens_to_keep: int = pipeline_kwargs.get("min_tokens_to_keep", 1)
top_k: int = pipeline_kwargs.get("top_k", 0)

prompt = self.tokenizer.encode(prompt, return_tensors="np")

Expand All @@ -223,7 +230,7 @@ def _stream(
detokenizer = self.tokenizer.detokenizer
detokenizer.reset()

sampler = make_sampler(temp or 0.0, top_p, min_p, min_tokens_to_keep)
sampler = make_sampler(temp or 0.0, top_p, min_p, min_tokens_to_keep, top_k)

logits_processors = make_logits_processors(
None, repetition_penalty, repetition_context_size
Expand Down