Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 11 min read How-to easyNovice

Total noob’s intro to Hugging Face Transformers

A beginner-oriented walkthrough of running Microsoft's Phi-2 language model with the Hugging Face Transformers library inside a JupyterLab notebook hosted on a Hugging Face Space with an NVIDIA A10G GPU. It explains foundational concepts along the way (libraries, the Hub, Spaces, classes, methods, tokenizers, instruction-tuned vs base models) and shows the minimal code: install torch and transformers, load the model and tokenizer with from_pretrained, tokenize a prompt, call generate with max_new_tokens, and decode the output. Because Phi-2 is a base model, its output reads like autocomplete rather than a chat reply.

Related posts

  • Hugging Face x LangChain : A new partner package

    Hugging Face mediumAdept

    langchain-huggingface is a new Python partner package jointly maintained by Hugging Face and LangChain, replacing community-written integrations that had drifted out of date. It provides HuggingFacePipeline for running transformers models locally, HuggingFaceEndpoint for the serverless Inference API or deployed TGI endpoints via InferenceClient, and ChatHuggingFace, which turns message lists into model-specific prompts with tokenizer.apply_chat_template. For embeddings it offers HuggingFaceEmbeddings (local sentence-transformers) and HuggingFaceEndpointEmbeddings (Hub or TEI instances), each shown with short code examples.

  • Hugging Face Text Generation Inference available for AWS Inferentia2

    Hugging Face mediumAdept

    Text Generation Inference (TGI) is now generally available on AWS Inferentia2 through Amazon SageMaker, offering an alternative to GPUs for serving open LLMs such as Llama and Mistral. A walkthrough deploys Zephyr 7B on an ml.inf2.8xlarge using the TGI Neuronx container. Because Inferentia2 lacks dynamic shapes, batch size, sequence length, core count and cast type must be fixed at compile time. A neuron model cache provides pre-compiled configurations; compiling an uncached one with optimum-cli can take up to 45 minutes. The deployment environment variables (HF_NUM_CORES, HF_BATCH_SIZE, HF_SEQUENCE_LENGTH, MAX_TOTAL_TOKENS) must match those compile-time settings.

  • Deploy LLMs with Hugging Face Inference Endpoints

    Hugging Face mediumAdept

    Falcon 40B Instruct can be deployed to Hugging Face Inference Endpoints through the web UI by choosing a repository, cloud, region and instance. For best performance the suggested 4x T4 instance should be switched to a single A100. Once the endpoint is live it can be called with cURL, and generation is controlled through parameters such as temperature, max_new_tokens (max 512), top_k/top_p, repetition_penalty and stop sequences. Tokens can be streamed to clients using huggingface_hub's InferenceClient in Python or HfInferenceEndpoint from @huggingface/inference in JavaScript, with code that skips special tokens and stops on stop sequences.

  • Timm ❤️ Transformers: Use any timm model with transformers

    Hugging Face mediumAdept

    TimmWrapper lets any timm vision model load through Hugging Face transformers' Auto classes and pipeline API. That makes architectures with no native transformers implementation, like MobileNetV4, usable with the standard tooling. Code examples cover pipeline inference, a Gradio demo, 8-bit quantization with bitsandbytes (346 MB to 88 MB, about 75% smaller, with near-identical predictions), Trainer-based fine-tuning and LoRA via PEFT (0.77% of parameters trainable), and torch.compile benchmarking. Fine-tuned models round-trip back into timm via the Hub with timm.create_model.

  • Hosting your Models and Datasets on Hugging Face Spaces using Streamlit

    Hugging Face mediumAdept

    Streamlit apps can showcase Hugging Face models and datasets and be hosted on Hugging Face Spaces. The walkthrough recreates "Write with Transformer" using Streamlit widgets such as text_area, sidebar sliders and number_input to collect generation hyperparameters like temperature, top-k and top-p. It then visualizes a poetry dataset, loaded with 🤗 Datasets streaming, using st.dataframe, st.bar_chart and st.pyplot for seaborn/matplotlib plots. Deployment means dragging files into a Space, listing dependencies in requirements.txt, and matching the Streamlit version.

The quest for software engineering knowledge.

Look:
Layout: