Skip to content

Conversation

@georgeykalangi
Copy link

Fixes #28226

The issue was that init_chat_model didn't properly handle HuggingFace model initialization. The main problems were:

  1. HuggingFacePipeline.from_model_id requires a 'task' parameter, but it wasn't being provided (defaults to 'text-generation' for chat models)

  2. Parameters needed to be properly separated between HuggingFacePipeline and ChatHuggingFace - generation parameters (temperature, max_tokens, etc.) should go to pipeline_kwargs, while other parameters (timeout, max_retries) should go to ChatHuggingFace

  3. max_tokens needs to be mapped to max_new_tokens for HuggingFace pipeline

Changes:

  • Extract task parameter with default 'text-generation'
  • Properly separate pipeline-specific kwargs from ChatHuggingFace kwargs
  • Map generation parameters to pipeline_kwargs
  • Map max_tokens to max_new_tokens for HuggingFace pipeline
  • Add test to verify the fix works correctly

(Replace this entire block of text)

Thank you for contributing to LangChain! Follow these steps to mark your pull request as ready for review. If any of these steps are not completed, your PR will not be considered for review.

  • PR title: Follows the format: {TYPE}({SCOPE}): {DESCRIPTION}

    • Examples:
      • feat(core): add multi-tenant support
      • fix(cli): resolve flag parsing error
      • docs(openai): update API usage examples
    • Allowed {TYPE} values:
      • feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert, release
    • Allowed {SCOPE} values (optional):
      • core, cli, langchain, standard-tests, text-splitters, docs, anthropic, chroma, deepseek, exa, fireworks, groq, huggingface, mistralai, nomic, ollama, openai, perplexity, prompty, qdrant, xai, infra
    • Once you've written the title, please delete this checklist item; do not include it in the PR.
  • PR message: Delete this entire checklist and replace with

  • Lint and test: Run make format, make lint and make test from the root of the package(s) you've modified. We will not consider a PR unless these three are passing in CI. See contribution guidelines for more.

Additional guidelines:

  • Most PRs should not touch more than one package.
  • Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. Likewise, please do not update the uv.lock files unless you are adding a required dependency.
  • Changes should be backwards compatible.
  • Make sure optional dependencies are imported within a function.

@georgeykalangi georgeykalangi force-pushed the fix/init-chat-model-huggingface-28226 branch from 6de174a to 247eee9 Compare November 13, 2025 05:31
@georgeykalangi georgeykalangi changed the title fix(chat_models): fix init_chat_model for HuggingFace models fix(langchain-classic): fix init_chat_model for HuggingFace models Nov 13, 2025
@github-actions github-actions bot added the fix label Nov 13, 2025
@georgeykalangi georgeykalangi force-pushed the fix/init-chat-model-huggingface-28226 branch from 247eee9 to 0a7e86f Compare November 13, 2025 05:36
Fixes langchain-ai#28226

The issue was that init_chat_model didn't properly handle HuggingFace
model initialization. The main problems were:

1. HuggingFacePipeline.from_model_id requires a 'task' parameter, but
   it wasn't being provided (defaults to 'text-generation' for chat models)

2. Parameters needed to be properly separated between HuggingFacePipeline
   and ChatHuggingFace - generation parameters (temperature, max_tokens,
   etc.) should go to pipeline_kwargs, while other parameters (timeout,
   max_retries) should go to ChatHuggingFace

3. max_tokens needs to be mapped to max_new_tokens for HuggingFace pipeline

Changes:
- Extract task parameter with default 'text-generation'
- Properly separate pipeline-specific kwargs from ChatHuggingFace kwargs
- Map generation parameters to pipeline_kwargs
- Map max_tokens to max_new_tokens for HuggingFace pipeline
- Add test to verify the fix works correctly
@georgeykalangi georgeykalangi force-pushed the fix/init-chat-model-huggingface-28226 branch from 3bc91cb to 77b2b70 Compare November 14, 2025 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

init_chat_model doesn't work with huggingface models

1 participant